https://github.com/HBN3tw0rk/dcache/tree/master#multiple-backends
Ideia:
from dcache import dcache
from dcache.backends import InMemoryBackend, RedisBackend
@dcache(multiple=[
InMemoryBackend(),
RedisBackend(host='localhost', port=6379, db=0),
])
def slow_function(n):
return n ** 1000
- search on the in-memory cache;
- if exists, return, if not, search on Redis;
-
- if exists on Redis, save in memory and return;
-
- if not, exists on Redis, run the
slow_function, save on Redis, save in-memory and return;
- doesn't run if already returned