Introduce V2 of current and historical functions
This commit is contained in:
28
wow_token/db/cache.py
Normal file
28
wow_token/db/cache.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import datetime
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
from wow_token.db.cached_range import CachedRange
|
||||
from wow_token.db.trinity import Trinity
|
||||
|
||||
|
||||
class Cache:
|
||||
_cache : Dict[str, List[Tuple[datetime.datetime, int]]]
|
||||
_db : 'Compacted'
|
||||
|
||||
def __init__(self, compacted_db: 'Compacted'):
|
||||
self._db = compacted_db
|
||||
self._cache = {}
|
||||
|
||||
|
||||
def get_month(self, trinity: Trinity) -> List[Tuple[datetime.datetime, int]]:
|
||||
current_time = datetime.datetime.now(datetime.UTC)
|
||||
if isinstance(trinity.range, CachedRange):
|
||||
raise NotImplementedError
|
||||
|
||||
current_month = trinity.range.month == current_time.month and trinity.range.year == current_time.year
|
||||
|
||||
if not current_month and str(trinity) in self._cache:
|
||||
return self._cache[str(trinity)]
|
||||
|
||||
self._cache[str(trinity)] = self._db.ddb_get_data(trinity)
|
||||
return self._cache[str(trinity)]
|
||||
Reference in New Issue
Block a user