uWSGI Backend¶
- class cachelib.uwsgi.UWSGICache(default_timeout=300, cache='', ignore_delete_many_errors=True)¶
Bases:
BaseCacheImplements the cache using uWSGI’s caching framework.
Note
This class cannot be used when running under PyPy, because the uWSGI API implementation for PyPy is lacking the needed functionality.
- Parameters:
default_timeout (int | timedelta) –
The default timeout, either a number of seconds or a
datetime.timedelta.Changed in version 0.17.0: Accepts a
datetime.timedelta.cache (str) – The name of the caching instance to connect to, for example: mycache@localhost:3031, defaults to an empty string, which means uWSGI will cache in the local instance. If the cache is in the same instance as your app, you only have to provide the name of the cache.
ignore_delete_many_errors (bool) –
If False, delete_many() will raise a RuntimeError if any key fails to delete. Keys that do not exist are considered successfully deleted and do not raise.
Changelog
Added in version 0.16.0.
- serializer = <cachelib.serializers.UWSGISerializer object>¶
- get(key)¶
Look up key in the cache and return the value for it.
- delete(key)¶
Delete
keyfrom the cache.
- set(key, value, timeout=None)¶
Add a new key/value to the cache (overwrites value, if key already exists in the cache).
- Parameters:
key (str) – the key to set
value (Any) – the value for the key
timeout (int | timedelta | None) – the cache timeout for the key, either a number of seconds or a
datetime.timedelta(if not specified, it uses the default timeout). A timeout of 0 indicates that the cache never expires.
- Returns:
Trueif key has been updated,Falsefor backend errors. Pickling errors, however, will raise a subclass ofpickle.PickleError.- Return type:
Literal[True] | None
- add(key, value, timeout=None)¶
Works like
set()but does not overwrite the values of already existing keys.- Parameters:
key (str) – the key to set
value (Any) – the value for the key
timeout (int | timedelta | None) – the cache timeout for the key, either a number of seconds or a
datetime.timedelta(if not specified, it uses the default timeout). A timeout of 0 indicates that the cache never expires.
- Returns:
Same as
set(), but alsoFalsefor already existing keys.- Return type:
- clear()¶
Clears the cache. Keep in mind that not all caches support completely clearing the cache.
- Returns:
Whether the cache has been cleared.
- Return type: