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:
logging_enabled()andverbose_logging()follow theCACHE_LOGGINGwaffle switch andsmarter_settings.verbose_logging.SmarterCacheKeyEncoderalso accepts Pydantic urls and models as cache key arguments.
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:
CacheKeyEncoderCache key encoder that also accepts Pydantic urls and models.
A model is identified by its class and its JSON dump, like a dataclass.
- smarter.lib.cache.hooks.logging_enabled()[source]
Whether to log every cache hit, miss and invalidation: the
CACHE_LOGGINGwaffle switch.- Returns:
True if the switch is on.
- Return type:
- 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: