def test_time_based_cache_middleware_expires_old_values( w3_base, result_generator_middleware): w3 = w3_base w3.middleware_stack.add(result_generator_middleware) def cache_class(): return { generate_cache_key(('fake_endpoint', [1])): ( time.time() - 10, { 'result': 'value-a' }, ), } w3.middleware_stack.add( construct_time_based_cache_middleware( cache_class=cache_class, cache_expire_seconds=10, rpc_whitelist={'fake_endpoint'}, )) result = w3.manager.request_blocking('fake_endpoint', [1]) assert result != 'value-a' assert w3.manager.request_blocking('fake_endpoint', [1]) == result
def test_time_based_cache_middleware_pulls_from_cache(w3_base): w3 = w3_base def cache_class(): return { generate_cache_key(('fake_endpoint', [1])): ( time.time(), {'result': 'value-a'}, ), } w3.middleware_stack.add(construct_time_based_cache_middleware( cache_class=cache_class, cache_expire_seconds=10, rpc_whitelist={'fake_endpoint'}, )) assert w3.manager.request_blocking('fake_endpoint', [1]) == 'value-a'
def test_time_based_cache_middleware_pulls_from_cache(w3_base): w3 = w3_base def cache_class(): return { generate_cache_key(('fake_endpoint', [1])): ( time.time(), {'result': 'value-a'}, ), } w3.middleware_stack.add(construct_time_based_cache_middleware( cache_class=cache_class, cache_expire_seconds=10, rpc_whitelist={'fake_endpoint'}, )) assert w3.manager.request_blocking('fake_endpoint', [1]) == 'value-a'
def test_time_based_cache_middleware_expires_old_values(w3_base, result_generator_middleware): w3 = w3_base w3.middleware_stack.add(result_generator_middleware) def cache_class(): return { generate_cache_key(('fake_endpoint', [1])): ( time.time() - 10, {'result': 'value-a'}, ), } w3.middleware_stack.add(construct_time_based_cache_middleware( cache_class=cache_class, cache_expire_seconds=10, rpc_whitelist={'fake_endpoint'}, )) result = w3.manager.request_blocking('fake_endpoint', [1]) assert result != 'value-a' assert w3.manager.request_blocking('fake_endpoint', [1]) == result
def time_cache_middleware(): return construct_time_based_cache_middleware( cache_class=dict, cache_expire_seconds=10, rpc_whitelist={'fake_endpoint'}, )
def time_cache_middleware(): return construct_time_based_cache_middleware( cache_class=dict, cache_expire_seconds=10, rpc_whitelist={'fake_endpoint'}, )