"Fossies" - the Fresh Open Source Software Archive

Member "keystone-18.0.0/doc/source/contributor/caching-layer.rst" (14 Oct 2020, 3660 Bytes) of package /linux/misc/openstack/keystone-18.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field. See also the latest Fossies "Diffs" side-by-side code changes report for "caching-layer.rst": 17.0.0_vs_18.0.0.

Caching Layer

The caching layer is designed to be applied to any manager object within Keystone via the use of keystone.common.cache module. This leverages oslo.cache caching system to provide a flexible caching backend.

The caching can be setup for all or some subsystems. It is recommended that each of the managers have an independent toggle within the config file to enable caching. The easiest method to utilize the toggle within the configuration file is to define a caching boolean option within that manager's configuration section (e.g. identity). Enable the global cache enabled option as well as the specific manager's caching enable toggle in order to cache that subsystem.

The oslo.cache is simple and easy to adopt by any system. See the usage guide of it. There are various cache backends <caching_layer> supported by it. Example use of oslo.cache in keystone (in this example, token is the manager):

from keystone.common import cache

TOKENS_REGION = cache.create_region(name='tokens')
MEMOIZE_TOKENS = cache.get_memoization_decorator(
    group='token',
    region=TOKENS_REGION)

@MEMOIZE_TOKENS
def _validate_token(self, token_id):
    ...
    return token

With the above example, each call to the cacheable_function would check to see if the arguments passed to it matched a currently valid cached item. If the return value was cached, the caching layer would return the cached value; if the return value was not cached, the caching layer would call the function, pass the value to the MEMOIZE_TOKEN decorator, which would then determine if caching was globally enabled and enabled for the token manager. If either caching toggle is disabled, the value is returned but not cached.

It is recommended that each of the managers have an independent configurable time-to-live (TTL). The option cache_time is to be set for every manager under its section in keystone.conf file. If the cache_time is set to None, the expiration time will be set to the global default expiration_time option in the [cache] configuration section. These options are passed to and handled by oslo.cache.

Cache invalidation <cache_invalidation> can be done if specific cache entries are changed. Example of invalidating a cache (in this example, token is the manager):

def invalidate_individual_token_cache(self, token_id):
    ...
    self._validate_token.invalidate(self, token_id)

For cache invalidation, there is an invalidate method (attribute) on the decorated function. To invalidate the cache, pass the same arguments to the invalidate method as you would the normal function. This means you need to pass self as the first argument.