forked from javatarz/github-contribution-leaderboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(javatarz#12): addition of redis in pipfile, cache duration in arg…
…s instead of having constant
- Loading branch information
Sathia
committed
Oct 19, 2019
1 parent
c8f7173
commit 84d01bc
Showing
3 changed files
with
22 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,24 @@ | ||
import redis | ||
|
||
|
||
def singleton(class_): | ||
instances = {} | ||
|
||
def getinstance(*args, **kwargs): | ||
if class_ not in instances: | ||
instances[class_] = class_(*args, **kwargs) | ||
return instances[class_] | ||
return getinstance | ||
|
||
|
||
@singleton | ||
class Cache: | ||
CACHE_DURATION_IN_SECONDS = 60 | ||
|
||
def __init__(self): | ||
self.redis = redis.Redis() | ||
def __init__(self, cache_duration=60): | ||
self.redis = redis.Redis() | ||
self.cache_duration=cache_duration | ||
|
||
def exists(self, cache_key) -> bool: | ||
return self.redis.exists(cache_key) | ||
def exists(self, cache_key) -> bool: | ||
return self.redis.exists(cache_key) | ||
|
||
def set(self, cache_key, value) -> bool: | ||
return self.redis.set(cache_key, value, self.CACHE_DURATION_IN_SECONDS) | ||
def set(self, cache_key, value) -> bool: | ||
return self.redis.set(cache_key, value, self.cache_duration) | ||
|
||
def fetch(self, cache_key) -> str: | ||
return self.redis.get(cache_key) | ||
def fetch(self, cache_key) -> str: | ||
return self.redis.get(cache_key) |