collective.redismemoize.adapter#
The cache adapter that stores values in Redis, or in RAM.
The cache adapter plone.memoize reads and writes through.
plone.memoize.volatile.cache needs a mapping with get,
__getitem__ and __setitem__. RedisCacheAdapter provides
them for one cached function, and decides per value where it goes:
plain data, within the size limit, goes to Redis with a TTL;
anything else goes to the stock RAM cache it wraps, and a refusal routes the whole function to RAM for the rest of the process;
a Redis failure is a miss, never an error, and opens the circuit breaker.
A read asks Redis first and the RAM cache after a Redis miss, because a value too large for Redis, or stored while the breaker was open, lives in RAM.
Values read from Redis are copies. A caller that mutates a cached value no longer mutates the cache, which the RAM cache allowed.
- class collective.redismemoize.adapter.RedisCacheAdapter[source]#
Bases:
AbstractDictStore one function's values in Redis, or in RAM when they cannot be.
- Parameters:
globalkey -- Dotted name of the cached function.
settings -- The package settings.
ram -- The stock RAM adapter for the same function.
router -- Per-function routes and counters.
connection -- The Redis connection and its breaker.
ttl -- Lifetime of a stored value;
settings.ttlwhen omitted.