This repository has been archived by the owner on Dec 23, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from jmcarp/feature/respect-caching-headers
Respect caching headers from API.
- Loading branch information
Showing
6 changed files
with
44 additions
and
20 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
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
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,6 +1,30 @@ | ||
import datetime | ||
import threading | ||
|
||
import cachetools | ||
import cachecontrol | ||
|
||
|
||
def current_cycle(): | ||
year = datetime.datetime.now().year | ||
return year + year % 2 | ||
|
||
|
||
class LRUCache(cachecontrol.cache.BaseCache): | ||
"""A thread-safe least recently updated cache adapted to work with | ||
Cache-Control. | ||
""" | ||
def __init__(self, maxsize): | ||
self.lock = threading.Lock() | ||
self.data = cachetools.LRUCache(maxsize) | ||
|
||
def get(self, key): | ||
return self.data.get(key, None) | ||
|
||
def set(self, key, value): | ||
with self.lock: | ||
self.data[key] = value | ||
|
||
def delete(self, key): | ||
with self.lock: | ||
self.data.clear() |
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