Skip to content

Commit f0a5b95

Browse files
committed
feat: add FtTTLCache to avoid mocking issues
overrides timer in a central location.
1 parent 54840a3 commit f0a5b95

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

freqtrade/util/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
round_value,
2323
)
2424
from freqtrade.util.ft_precise import FtPrecise
25+
from freqtrade.util.ft_ttlcache import FtTTLCache
2526
from freqtrade.util.measure_time import MeasureTime
2627
from freqtrade.util.periodic_cache import PeriodicCache
2728
from freqtrade.util.progress_tracker import ( # noqa F401
@@ -59,4 +60,5 @@
5960
"print_rich_table",
6061
"print_df_rich_table",
6162
"CustomProgress",
63+
"FtTTLCache",
6264
]

freqtrade/util/ft_ttlcache.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import time
2+
3+
from cachetools import TTLCache
4+
5+
6+
class FtTTLCache(TTLCache):
7+
"""
8+
A TTLCache with a different default timer to allow for easier mocking in tests.
9+
"""
10+
11+
def __init__(self, maxsize, ttl, timer=time.time, getsizeof=None):
12+
super().__init__(maxsize=maxsize, ttl=ttl, timer=timer, getsizeof=getsizeof)

0 commit comments

Comments
 (0)