Caching Layer Implementation.
To use this library:
You must call configure().
Inside your application code, decorate the methods that you want the results to be cached with a memoization decorator created with get_memoization_decorator(). This function takes a group name from the config. Register [group] caching and [group] cache_time options for the groups that your decorators use so that caching can be configured.
This library’s configuration options must be registered in your application’s oslo_config.cfg.ConfigOpts instance. Do this by passing the ConfigOpts instance to configure().
The library has special public value for nonexistent or expired keys called NO_VALUE. To use this value you should import it from oslo_cache.core:
from oslo_cache import core
NO_VALUE = core.NO_VALUE
Configure the library.
Register the required oslo.cache config options into an oslo.config CONF object.
This must be called before configure_cache_region().
Parameters: | conf (oslo_config.cfg.ConfigOpts) – The configuration object. |
---|
Configure a cache region.
If the cache region is already configured, this function does nothing. Otherwise, the region is configured.
Parameters: |
|
---|---|
Raises oslo_cache.exception.ConfigurationError: | |
If the region parameter is not a dogpile.cache.CacheRegion. |
|
Returns: | The region. |
Return type: |
Create a region.
This is just dogpile.cache.make_region, but the key generator has a different to_str mechanism.
Note
You must call configure_cache_region() with this region before a memoized method is called.
Returns: | The new region. |
---|---|
Return type: | dogpile.cache.region.CacheRegion |
Build a function based on the cache_on_arguments decorator.
The memoization decorator that gets created by this function is a dogpile.cache.region.CacheRegion.cache_on_arguments() decorator, where
Example usage:
import oslo_cache.core
MEMOIZE = oslo_cache.core.get_memoization_decorator(conf,
group='group1')
@MEMOIZE
def function(arg1, arg2):
...
ALTERNATE_MEMOIZE = oslo_cache.core.get_memoization_decorator(
conf, group='group2', expiration_group='group3')
@ALTERNATE_MEMOIZE
def function2(arg1, arg2):
...
Parameters: |
|
---|---|
Return type: | function reference |
Value returned for nonexistent or expired keys.
Bases: exceptions.Exception
Raised when the cache isn’t configured correctly.
Bases: exceptions.Exception
Raised when a connection cannot be acquired.
Items useful for external testing.
Bases: dogpile.cache.proxy.ProxyBackend
Proxy that forces a memory copy of stored values.
The default in-memory cache-region does not perform a copy on values it is meant to cache. Therefore if the value is modified after set or after get, the cached value also is modified. This proxy does a copy as the last thing before storing data.
In your application’s tests, you’ll want to set this as a proxy for the in-memory cache, like this:
self.config_fixture.config(
group='cache',
backend='dogpile.cache.memory',
enabled=True,
proxies=['oslo_cache.testing.CacheIsolatingProxy'])
Configure the library.
Register the required oslo.cache config options into an oslo.config CONF object.
This must be called before configure_cache_region().
Parameters: | conf (oslo_config.cfg.ConfigOpts) – The configuration object. |
---|
Configure a cache region.
If the cache region is already configured, this function does nothing. Otherwise, the region is configured.
Parameters: |
|
---|---|
Raises oslo_cache.exception.ConfigurationError: | |
If the region parameter is not a dogpile.cache.CacheRegion. |
|
Returns: | The region. |
Return type: |
Create a region.
This is just dogpile.cache.make_region, but the key generator has a different to_str mechanism.
Note
You must call configure_cache_region() with this region before a memoized method is called.
Returns: | The new region. |
---|---|
Return type: | dogpile.cache.region.CacheRegion |
Build a function based on the cache_on_arguments decorator.
The memoization decorator that gets created by this function is a dogpile.cache.region.CacheRegion.cache_on_arguments() decorator, where
Example usage:
import oslo_cache.core
MEMOIZE = oslo_cache.core.get_memoization_decorator(conf,
group='group1')
@MEMOIZE
def function(arg1, arg2):
...
ALTERNATE_MEMOIZE = oslo_cache.core.get_memoization_decorator(
conf, group='group2', expiration_group='group3')
@ALTERNATE_MEMOIZE
def function2(arg1, arg2):
...
Parameters: |
|
---|---|
Return type: | function reference |