collective.redismemoize.api

collective.redismemoize.api#

Invalidation, status, and a decorator with its own TTL. This is the module add-ons call.

Public API: invalidation, status, and a decorator with its own TTL.

Nothing in this package calls invalidate_all() on its own. Call it when the meaning of cached values changes for every instance at once, typically after a deploy that changes what a cached function returns, or from an upgrade step.

collective.redismemoize.api.BATCH_SIZE = 500#

How many keys one SCAN step asks for, and one UNLINK removes.

collective.redismemoize.api.ram_caches()[source]#

Return the RAM caches plone.memoize may have stored values in.

The chooser wraps the IRAMCache utility, while store_in_cache falls back to global_cache when no chooser is registered. They are usually the same object, but not always: a test layer can register its own.

Returns:

global_cache, and the utility when it is a different cache.

Return type:

list[Any]

collective.redismemoize.api.invalidate(fun_name)[source]#

Drop every cached value of one function, in Redis and in RAM.

Parameters:

fun_name (str) -- Dotted name of the cached function, as module.function.

Returns:

How many Redis keys were removed.

Return type:

int

collective.redismemoize.api.invalidate_all()[source]#

Drop every cached value under the prefix, and the whole RAM cache.

Returns:

How many Redis keys were removed.

Return type:

int

collective.redismemoize.api.status()[source]#

Describe the configuration, the breaker, the server and the routes.

This contacts Redis (a PING and an INFO server) even while the breaker is open, so it reports the server's current state.

Returns:

A JSON-serializable mapping.

Return type:

dict[str, Any]

collective.redismemoize.api.cache(get_key, ttl=None)[source]#

Decorate a function like plone.memoize.ram.cache, with its own TTL.

The value goes through the same chooser, serializer and routing as any other cached function; ttl only matters when it ends up in Redis.

Parameters:
  • get_key (Callable[[...], Any]) -- Builds the cache key, as for plone.memoize.ram.cache.

  • ttl (int | None) -- Lifetime in seconds; the configured default when omitted.

Returns:

The decorator.

Raises:

ValueError -- When ttl is not a positive integer.

Return type:

Callable