Settings
Configuration of the @cache_results decorator, read from the.
CACHE_RESULTS Django setting. Every entry is optional:
CACHE_RESULTS = {
# the CACHES alias that holds cached results.
"CACHE_ALIAS": "default",
# the default timeout, in seconds, of a decorated function that names none.
# Unset, it is the cache alias's own TIMEOUT.
"TIMEOUT": 3600,
# text that starts every key. Changing it, or VERSION, abandons every cached
# result at once, without touching anything else in the same cache.
"KEY_PREFIX": "",
"VERSION": None,
# a subclass of cache_results.keys.CacheKeyEncoder, to allow more argument types.
"KEY_ENCODER": "cache_results.keys.CacheKeyEncoder",
# zero-argument callables that return whether to log cache hits, misses and
# invalidations, and whether those logs include the arguments.
"LOGGING_ENABLED": None,
"VERBOSE_LOGGING": None,
# a callable(text, event) that formats the start of each log message, where
# event is "hit", "miss", "invalidate" or "".
"LOG_PREFIX": None,
}
Callables and classes are given as dotted paths, or as the objects
themselves. Settings are read on every call, so override_settings works in
tests. This module depends only on Django and the standard library.
- class cache_results.conf.CacheResultsSettings[source]
Bases:
objectThe
CACHE_RESULTSsetting, with its defaults.Use the module’s
cache_results_settingsinstance.- property timeout: float | None
The default timeout in seconds, or Django’s
DEFAULT_TIMEOUTmarker, which means the cache alias’s own.- Return type:
Optional[float]
- property key_prefix: str
Text that starts every key:
KEY_PREFIX, thenv<VERSION>:when a version is set.- Return type:
- property key_encoder: type[CacheKeyEncoder]
The JSON encoder for arguments.
- Return type:
- Raises:
TypeError – If the setting doesn’t name a subclass of
CacheKeyEncoder.
- property logging_enabled: bool
Whether to log every cache hit, miss and invalidation, from
LOGGING_ENABLED.- Return type:
- cache_results.conf.LOG_EVENTS = ('hit', 'miss', 'invalidate', '')
The events that a
LOG_PREFIXcallable is called with.
- cache_results.conf.SETTING_NAME = 'CACHE_RESULTS'
The name of the Django setting that configures
@cache_results.
- cache_results.conf.cache_results_settings = <cache_results.conf.CacheResultsSettings object>
The
CACHE_RESULTSsetting, with its defaults.