29 lines
911 B
Python
29 lines
911 B
Python
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)]
|