get¶
-
privex.helpers.cache.
get
(key: str, default: Any = None, fail: bool = False) → Any[source]¶ Return the value of cache key
key
. If the key wasn’t found, or it was expired, thendefault
will be returned.Optionally, you may choose to pass
fail=True
, which will cause this method to raiseCacheNotFound
instead of returningdefault
when a key is non-existent / expired.- Parameters
key (str) – The cache key (as a string) to get the value for, e.g.
example:test
default (Any) – If the cache key
key
isn’t found / is expired, return this value (Default:None
)fail (bool) – If set to
True
, will raiseCacheNotFound
instead of returningdefault
when a key is non-existent / expired.
- Raises
CacheNotFound – Raised when
fail=True
andkey
was not found in cache / expired.- Return Any value
The value of the cache key
key
, ordefault
if it wasn’t found.