collective.redismemoize.routing#
Per-function routes and counters.
Where each cached function's values live, and what happened to them.
Routing is decided per function, for the lifetime of the process. A function whose value was refused once is kept in RAM from then on: the next call does not pay for another serialization attempt and a Redis round-trip only to be refused again. Size is the exception and is decided per value, because the size of a value varies from call to call while its type rarely does.
The counters are what an operator reads to make the one judgement this package cannot make: a value can be plain data and still be wrong to share, when its cache key leaves out something that differs between instances.
This module is pure Python and never imports Zope.
- class collective.redismemoize.routing.Route[source]#
Bases:
EnumWhere a function's values are stored.
- REDIS = 'redis'#
Shared, in Redis. The default for every function not routed elsewhere.
- RAM_EXCLUDED = 'ram-excluded'#
In the RAM cache, because the configuration excludes the function.
- RAM_NOT_SHAREABLE = 'ram-not-shareable'#
In the RAM cache, because one of its values was not plain data.
- collective.redismemoize.routing.COUNTERS = ('redis_hits', 'redis_misses', 'ram_hits', 'ram_misses', 'refused', 'too_large', 'undecodable', 'errors')#
The counters kept per function, in the order they are reported.
- class collective.redismemoize.routing.Router[source]#
Bases:
objectPer-process routes and counters, safe to use from several threads.
- route_for(fun_name)[source]#
Return the route of a function.
- Parameters:
fun_name (str) -- Dotted name of the cached function.
- Returns:
The learned route, or
Route.REDIS.- Return type:
- learn(fun_name, route, reason)[source]#
Route a function to RAM for the rest of the process.
The first route learned for a function wins; it is logged once.
- Parameters:
fun_name (str) -- Dotted name of the cached function.
route (Route) -- Where its values go from now on.
reason (str) -- Why, for the log and for
snapshot().
- Returns:
Whether this call changed the route.
- Return type:
- count(fun_name, counter)[source]#
Add one to a counter.
- Parameters:
- Raises:
ValueError -- For a counter that does not exist.
- Return type:
None
- collective.redismemoize.routing.router = <collective.redismemoize.routing.Router object>#
The process router.