How to use the xalpha.universal.lru_cache_time function in xalpha

To help you get started, we’ve selected a few xalpha examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github refraction-ray / xalpha / tests / test_universal.py View on Github external
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
github refraction-ray / xalpha / doc / samples / qdiipred.py View on Github external
@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
github refraction-ray / xalpha / doc / samples / qdiipred.py View on Github external
@xa.universal.lru_cache_time(ttl=180)
def cached_get_rt(code, **kws):
    return xa.get_rt(code, handler=False)