Smarter cache_results Hooks

Smarter.lib.cache.hooks

Smarter’s hooks for the cache-results package.

The package (https://docs.cache-results.smarter.sh/) depends only on Django. Its CACHE_RESULTS setting, in smarter/settings/base.py, names these hooks, which connect it to the parts of Smarter that it can’t depend on:

Log messages are colored by the package’s own cache_results.colors.log_prefix().

class smarter.lib.cache.hooks.SmarterCacheKeyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: CacheKeyEncoder

Cache key encoder that also accepts Pydantic urls and models.

A model is identified by its class and its JSON dump, like a dataclass.

default(o)[source]

Encode one value that JSON doesn’t know.

Parameters:

o (object) – The value.

Returns:

A JSON-serializable representation of o.

Return type:

object

Raises:

cache_results.CacheKeyArgumentError – If o has no safe representation.

smarter.lib.cache.hooks.logging_enabled()[source]

Whether to log every cache hit, miss and invalidation: the CACHE_LOGGING waffle switch.

Returns:

True if the switch is on.

Return type:

bool

smarter.lib.cache.hooks.verbose_logging()[source]

Whether cache logs include the arguments: smarter_settings.verbose_logging.

The package asks only when logging_enabled() is True.

Returns:

True if verbose logging is on.

Return type:

bool