Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_cache_time():
class F:
def __init__(self):
self.r = 0
def __call__(self):
self.r += 1
return self.r
__name__ = "F"
f = xa.universal.lru_cache_time(ttl=5)(F())
assert f() == 1
assert f() == 1
time.sleep(5)
assert f() == 2
@xa.universal.lru_cache_time(ttl=1800)
def cached_get_bar(code, *args, **kws):
if code.startswith("commodities/"):
kws["handler"] = False
return xa.get_bar(code, *args, **kws)
return None
@xa.universal.lru_cache_time(ttl=180)
def cached_get_rt(code, **kws):
return xa.get_rt(code, handler=False)