async def test_cache_decorators_on_redis_down(): mock = Mock(return_value="val") cache = Cache() cache._add_backend(Redis, safe=True, address="redis://localhost:9223", hash_key=None) @cache(ttl=1) @cache.fail(1) @cache.hit(ttl=1, cache_hits=1) @cache.perf(ttl=1) @cache.circuit_breaker(ttl=1, errors_rate=1, period=1) @cache.rate_limit(ttl=1, limit=1, period=1) @cache.early(ttl=1) @cache.dynamic() @cache.locked(ttl=1) async def func(): return mock() assert await func() == "val" assert mock.call_count == 1 assert await func() == "val" assert mock.call_count == 2
def __cache(target): _cache = Cache() _cache._add_backend(Memory) _cache._backends[""] = (target, _cache._backends[""][1]) return _cache