wowtoken.app-backend

git clone https://git.emily.sh/wowtoken-app/wowtoken.app-backend.git
Log | Files | Refs | LICENSE

cache.py (911B)


      1 import datetime
      2 from typing import Dict, List, Tuple
      3 
      4 from wow_token.db.cached_range import CachedRange
      5 from wow_token.db.trinity import Trinity
      6 
      7 
      8 class Cache:
      9     _cache : Dict[str, List[Tuple[datetime.datetime, int]]]
     10     _db : 'Compacted'
     11 
     12     def __init__(self, compacted_db: 'Compacted'):
     13         self._db = compacted_db
     14         self._cache = {}
     15 
     16 
     17     def get_month(self, trinity: Trinity) -> List[Tuple[datetime.datetime, int]]:
     18         current_time = datetime.datetime.now(datetime.UTC)
     19         if isinstance(trinity.range, CachedRange):
     20             raise NotImplementedError
     21 
     22         current_month = trinity.range.month == current_time.month and trinity.range.year == current_time.year
     23 
     24         if not current_month and str(trinity) in self._cache:
     25             return self._cache[str(trinity)]
     26 
     27         self._cache[str(trinity)] = self._db.ddb_get_data(trinity)
     28         return self._cache[str(trinity)]