cache_get_or_set

classmethod CacheManagerMixin.cache_get_or_set(key: str, value: Any, timeout: Optional[Union[decimal.Decimal, int, float, str]] = <class 'privex.helpers.types.AutoDetected'>, auto_prefix=True)[source]

This is a simple helper method which calls cached.get_or_set() - while automatically prepending cache_prefix and cache_sep before the key.

Parameters
  • key (str) – The cache key (as a string) to get the value for, e.g. example:test

  • value (Any) – The value to store in the cache key key

  • timeout (int) – The amount of seconds to keep the data in cache. Pass None to disable expiration.

  • auto_prefix (bool) – If set to True, will auto-prepend cache_prefix to key if it’s not present.

Raises

CacheNotFound – Raised when fail=True and key was not found in cache / expired.

Return Any value

The value of the cache key key, or default if it wasn’t found.