shuup.core.cache package¶
Submodules¶
shuup.core.cache.impl module¶
-
shuup.core.cache.impl.
get_cache_duration
(cache_key)[source]¶ Determine a cache duration for the given cache key.
Parameters: cache_key (str) – Cache key string Returns: Timeout seconds Return type: int
-
class
shuup.core.cache.impl.
VersionedCache
(using)[source]¶ Bases:
object
Parameters: using (str) – Cache alias -
bump_version
(cache_key)[source]¶ Bump up the cache version for the given cache key/namespace.
Parameters: cache_key (str) – Cache key or namespace
-
get_version
(cache_key)[source]¶ Get the cache version (or None) for the given cache key/namespace.
The cache version is stored in thread-local storage for the current request, so unless bumped in-request, all gets within a single request should get coherently versioned data from the cache.
Parameters: cache_key (str) – Cache key or namespace Returns: Version ID or none Return type: str|None
-
set
(key, value, timeout=None, version=None)[source]¶ Set the value for key
key
in the cache.Unlike
django.core.caches[using].set()
, this also derives timeout and versioning information from the key (and cached version data) if the key begins with a colon-separated namespace, such asfoo:bar
.Parameters:
-
get
(key, version=None, default=None)[source]¶ Get the value for key
key
in the cache.Unlike
django.core.caches[using].get()
, versioning information can be auto-derived from the key (and cached version data) if the key begins with a colon-separated namespace, such asfoo:bar
.Parameters: Returns: cached value
Return type:
-
Module contents¶
Utilities for versioned caching and automatic timeout determination.
Versioning works by way of namespaces. Namespaces are the first colon-separated part of cache keys.
For instance, the cache keys price:10
, price:20
, and price
all belong to the price
namespace and can be invalidated with
one bump_version("price")
call.
The versions themselves are stored within the cache, within the
_version
namespace. (As an implementation detail, this allows one
to invalidate _all_ versioned keys by bumping the version of
_version
. Very meta!)
-
class
shuup.core.cache.
VersionedCache
(using)[source]¶ Bases:
object
Parameters: using (str) – Cache alias -
bump_version
(cache_key)[source]¶ Bump up the cache version for the given cache key/namespace.
Parameters: cache_key (str) – Cache key or namespace
-
get
(key, version=None, default=None)[source]¶ Get the value for key
key
in the cache.Unlike
django.core.caches[using].get()
, versioning information can be auto-derived from the key (and cached version data) if the key begins with a colon-separated namespace, such asfoo:bar
.Parameters: Returns: cached value
Return type:
-
get_version
(cache_key)[source]¶ Get the cache version (or None) for the given cache key/namespace.
The cache version is stored in thread-local storage for the current request, so unless bumped in-request, all gets within a single request should get coherently versioned data from the cache.
Parameters: cache_key (str) – Cache key or namespace Returns: Version ID or none Return type: str|None
-
set
(key, value, timeout=None, version=None)[source]¶ Set the value for key
key
in the cache.Unlike
django.core.caches[using].set()
, this also derives timeout and versioning information from the key (and cached version data) if the key begins with a colon-separated namespace, such asfoo:bar
.Parameters:
-