File Backend¶
- class cachelib.file.FileSystemCache(cache_dir, threshold=500, default_timeout=300, mode=None, hash_method=None)¶
Bases:
BaseCacheA cache that stores the items on the file system. This cache depends on being the only user of the
cache_dir. Make absolutely sure that nobody but this cache stores files there or otherwise the cache will randomly delete files therein.- Parameters:
cache_dir (str) – the directory where cache files are stored.
threshold (int) – the maximum number of items the cache stores before it starts deleting some. A threshold value of 0 indicates no threshold.
default_timeout (int) – the default timeout that is used if no timeout is specified on
set(). A timeout of 0 indicates that the cache never expires.mode (int | None) – the file mode wanted for the cache files, default 0600
hash_method (Any) – Default hashlib.md5. The hash method used to generate the filename for cached results. Default is lazy loaded and can be overridden by setting
_default_hash_method
- serializer = <cachelib.serializers.FileSystemSerializer object>¶
- 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
- get(key)¶
Look up key in the cache and return the value for it.
- add(key, value, timeout=None)¶
Works like
set()but does not overwrite the values of already existing keys.- Parameters:
- Returns:
Same as
set(), but alsoFalsefor already existing keys.- Return type:
boolean
- set(key, value, timeout=None, mgmt_element=False)¶
Add a new key/value to the cache (overwrites value, if key already exists in the cache).
- Parameters:
- Returns:
Trueif key has been updated,Falsefor backend errors. Pickling errors, however, will raise a subclass ofpickle.PickleError.- Return type:
boolean
- delete(key, mgmt_element=False)¶
Delete
keyfrom the cache.