feat: add FtTTLCache to avoid mocking issues

overrides timer in a central location.
This commit is contained in:
Matthias
2025-11-24 07:05:49 +01:00
parent 54840a3f7e
commit f0a5b95ec0
2 changed files with 14 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ from freqtrade.util.formatters import (
round_value, round_value,
) )
from freqtrade.util.ft_precise import FtPrecise from freqtrade.util.ft_precise import FtPrecise
from freqtrade.util.ft_ttlcache import FtTTLCache
from freqtrade.util.measure_time import MeasureTime from freqtrade.util.measure_time import MeasureTime
from freqtrade.util.periodic_cache import PeriodicCache from freqtrade.util.periodic_cache import PeriodicCache
from freqtrade.util.progress_tracker import ( # noqa F401 from freqtrade.util.progress_tracker import ( # noqa F401
@@ -59,4 +60,5 @@ __all__ = [
"print_rich_table", "print_rich_table",
"print_df_rich_table", "print_df_rich_table",
"CustomProgress", "CustomProgress",
"FtTTLCache",
] ]

View File

@@ -0,0 +1,12 @@
import time
from cachetools import TTLCache
class FtTTLCache(TTLCache):
"""
A TTLCache with a different default timer to allow for easier mocking in tests.
"""
def __init__(self, maxsize, ttl, timer=time.time, getsizeof=None):
super().__init__(maxsize=maxsize, ttl=ttl, timer=timer, getsizeof=getsizeof)