-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8ce719
commit c3eccce
Showing
2 changed files
with
32 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from expiringdict import ExpiringDict | ||
|
||
from src.searchly import CACHE_MAX_LENGTH, CACHE_MAX_AGE, CACHE_DICT_FORMAT | ||
|
||
|
||
__cache = ExpiringDict(max_len=CACHE_MAX_LENGTH, max_age_seconds=CACHE_MAX_AGE) # 5 minutes expiration | ||
|
||
|
||
def get(method, key): | ||
""" | ||
Get object from the cache given a method and key. | ||
:param method: Method. | ||
:param key: Key. | ||
:return: Cached object if found, None otherwise. | ||
""" | ||
return __cache.get(CACHE_DICT_FORMAT.format(method, key)) | ||
|
||
|
||
def refresh(method, key, refreshed_element): | ||
""" | ||
Refresh object in cache. | ||
:param method: Method. | ||
:param key: Key. | ||
:param refreshed_element: Object to refresh. | ||
:return: Object refreshed. | ||
""" | ||
__cache[CACHE_DICT_FORMAT.format(method, key)] = refreshed_element |