Move periodicCache to Utils package

This commit is contained in:
Matthias
2022-08-10 08:57:19 +00:00
parent 573964b19f
commit adc8ee88e2
6 changed files with 5 additions and 4 deletions

View File

@@ -0,0 +1,2 @@
# flake8: noqa: F401
from freqtrade.util.periodic_cache import PeriodicCache

View File

@@ -0,0 +1,19 @@
from datetime import datetime, timezone
from cachetools import TTLCache
class PeriodicCache(TTLCache):
"""
Special cache that expires at "straight" times
A timer with ttl of 3600 (1h) will expire at every full hour (:00).
"""
def __init__(self, maxsize, ttl, getsizeof=None):
def local_timer():
ts = datetime.now(timezone.utc).timestamp()
offset = (ts % ttl)
return ts - offset
# Init with smlight offset
super().__init__(maxsize=maxsize, ttl=ttl - 1e-5, timer=local_timer, getsizeof=getsizeof)