From f0a5b95ec032d933f15b2589a53c741aa8bd834b Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 24 Nov 2025 07:05:49 +0100 Subject: [PATCH] feat: add FtTTLCache to avoid mocking issues overrides timer in a central location. --- freqtrade/util/__init__.py | 2 ++ freqtrade/util/ft_ttlcache.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 freqtrade/util/ft_ttlcache.py diff --git a/freqtrade/util/__init__.py b/freqtrade/util/__init__.py index de8923389..06deb3ce0 100644 --- a/freqtrade/util/__init__.py +++ b/freqtrade/util/__init__.py @@ -22,6 +22,7 @@ from freqtrade.util.formatters import ( round_value, ) from freqtrade.util.ft_precise import FtPrecise +from freqtrade.util.ft_ttlcache import FtTTLCache from freqtrade.util.measure_time import MeasureTime from freqtrade.util.periodic_cache import PeriodicCache from freqtrade.util.progress_tracker import ( # noqa F401 @@ -59,4 +60,5 @@ __all__ = [ "print_rich_table", "print_df_rich_table", "CustomProgress", + "FtTTLCache", ] diff --git a/freqtrade/util/ft_ttlcache.py b/freqtrade/util/ft_ttlcache.py new file mode 100644 index 000000000..410184477 --- /dev/null +++ b/freqtrade/util/ft_ttlcache.py @@ -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)