Simple Memory Backend¶
- class cachelib.simple.SimpleCache(threshold=500, default_timeout=300)¶
Bases:
BaseCache
Simple memory cache for single process environments. This class exists mainly for the development server and is not 100% thread safe. It tries to use as many atomic operations as possible and no locks for simplicity but it could happen under heavy load that keys are added multiple times.
- Parameters
- add(key, value, timeout=None)¶
Works like
set()
but does not overwrite the values of already existing keys.- Parameters
- Returns
Same as
set()
, but alsoFalse
for already existing keys.- Return type
boolean
- 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
boolean
- delete(key)¶
Delete key from the cache.
- Parameters
key (str) – the key to delete.
- Returns
Whether the key existed and has been deleted.
- Return type
boolean
- get(key)¶
Look up key in the cache and return the value for it.
- has(key)¶
Checks if a key exists in the cache without returning it. This is a cheap operation that bypasses loading the actual data on the backend.
- serializer = <cachelib.serializers.SimpleSerializer object>¶
- set(key, value, timeout=None)¶
Add a new key/value to the cache (overwrites value, if key already exists in the cache).
- Parameters
- Returns
True
if key has been updated,False
for backend errors. Pickling errors, however, will raise a subclass ofpickle.PickleError
.- Return type
boolean