core.cache
Provides caching methods for onegov.core.
Onegov.core uses dogpile for caching: https://dogpilecache.readthedocs.org/
Unlike dogpile onegov.core does not provide a global region however. The cache is available through the app:
request.app.cache.set('key', 'value')
Global caches in a multi-tennant application are a security vulnerability waiting to be discovered. Therefore we do not do that!
This means that this won’t be available:
from x import cache
@cache.cache_on_arguments()
def my_function():
return 'foobar'
Syntactic sugar like this will be provided through decorators inside this module in the future. For example, we could write one that is usable on all morepath views:
@App.view(...)
@cache.view()
def my_view():
return '<html>...'
But no such method exists yet.
Currently there is one cache per app that never expires (though values will eventually be discarded by redis if the cache is full).
Attributes
Classes
A slightly more specific CacheRegion that will be configured |
Functions
Least-recently-used cache decorator for class methods. |
|
|
|
|
|
|
|
|
Module Contents
- core.cache.instance_lru_cache(*, maxsize: int | None = ...) Callable[[_F], _F] [source]
- core.cache.instance_lru_cache(method: _F, *, maxsize: int | None = ...) _F
Least-recently-used cache decorator for class methods.
The cache follows the lifetime of an object (it is stored on the object, not on the class) and can be used on unhashable objects.
This is a wrapper around functools.lru_cache which prevents memory leaks when using LRU cache within classes.
- class core.cache.RedisCacheRegion(namespace: str, expiration_time: float, redis_url: str)[source]
Bases:
dogpile.cache.CacheRegion
A slightly more specific CacheRegion that will be configured to a single non-clustered Redis backend with name-mangling based on a given namespace as well as a couple of additional convenience methods specific to Redis.
It will use dill to serialize/deserialize values.
- core.cache.get(namespace: str, expiration_time: float, redis_url: str) RedisCacheRegion [source]