-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cache aggregates by owner results until they are updated
- Loading branch information
1 parent
827832f
commit 6f3b217
Showing
2 changed files
with
50 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from collections import defaultdict | ||
|
||
|
||
class Cache: | ||
def __init__(self): | ||
self._cache = defaultdict(dict) | ||
|
||
def get(self, key, namespace): | ||
return self._cache[namespace].get(key) | ||
|
||
def set(self, key, value, namespace): | ||
self._cache[namespace][key] = value | ||
|
||
def exists(self, key, namespace): | ||
return key in self._cache[namespace] | ||
|
||
def delete_namespace(self, namespace): | ||
if namespace in self._cache: | ||
self._cache[namespace] = {} | ||
|
||
def delete(self, key, namespace): | ||
if self.exists(key, namespace): | ||
del self._cache[namespace] | ||
|
||
|
||
# simple in memory cache | ||
# we can't use aiocache here because most of ORM methods are not async compatible | ||
cache = Cache() |
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