Add PeriodicCache

This commit is contained in:
Matthias
2021-09-13 19:32:51 +02:00
parent 432c3df17e
commit 3cdd06f562
4 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
from datetime import datetime, timezone
from cachetools.ttl 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)

View File

@@ -1,5 +1,6 @@
# flake8: noqa: F401
from freqtrade.configuration.PeriodicCache import PeriodicCache
from freqtrade.configuration.check_exchange import check_exchange, remove_credentials
from freqtrade.configuration.config_setup import setup_utils_configuration
from freqtrade.configuration.config_validation import validate_config_consistency