liara.cache¶
Module Contents¶
Classes¶
Information about a cache. Note that the information can be approximated as getting the exact numbers may be costly. |
|
Interface for key-value caches. |
|
A |
|
A |
|
An in-memory |
|
A cache using Redis as the storage backend. |
|
The null cache drops all requests and does not cache any data. |
API¶
- class liara.cache.CacheInfo¶
Information about a cache. Note that the information can be approximated as getting the exact numbers may be costly.
- size: int = 0¶
Approximate number of bytes stored in the cache.
- entry_count: int = 0¶
Approximate number of objects stored in the cache.
- name: str = <Multiline-String>¶
A human-friendly name for this cache.
- class liara.cache.Cache¶
Bases:
abc.ABCInterface for key-value caches.
- abstractmethod set_key_prefix(prefix: bytes)¶
Set a prefix for all keys. This can be for example used to avoid collisions when the configuration changes (which can impact all values).
- abstractmethod put(key: bytes, value: object | bytes) bool¶
Put a value into the cache using the provided key.
- Parameters:
key – The key under which
valuewill be stored.value – A pickable Python object to be stored, or raw bytes.
- Returns:
Trueif the value was added to the cache,Falseif it was already cached.
- abstractmethod get(key: bytes) Optional[object | bytes]¶
Get a stored object.
- Parameters:
key – The object key.
- Returns:
An object if one exists. Otherwise, return
None.
- persist() None¶
Persists this cache to disk/persistent storage.
This function should be called after the cache has been populated. On the next run, the constructor will then pick up the index and return cached data.
- abstractmethod clear() None¶
Clear the contents of the cache.
Added in version 2.5.
- abstractmethod inspect() liara.cache.CacheInfo¶
Get an overview of the cached data.
Added in version 2.5.
- class liara.cache.FilesystemCache(path: pathlib.Path)¶
Bases:
liara.cache._CacheBaseA
Cacheimplementation which uses the filesystem to cache data.This cache tries to load a previously generated index. Use
persist()to write the cache index to disk.Initialization
- clear() None¶
- persist()¶
- inspect()¶
- class liara.cache.Sqlite3Cache(path: pathlib.Path)¶
Bases:
liara.cache._CacheBaseA
Cacheimplementation which uses SQLite to store the data. This is mostly useful if creating many files is slow, for instance due to anti-virus software.This cache tries to load a previously generated index. Use
persist()to write the cache index to disk.Initialization
- clear() None¶
- persist()¶
- inspect()¶
- class liara.cache.MemoryCache¶
Bases:
liara.cache._CacheBaseAn in-memory
Cacheimplementation.This cache stores all objects in-memory.
Initialization
- clear()¶
- inspect()¶
- class liara.cache.RedisCache(host: str, port: int, db: int, expiration_time=timedelta(hours=1))¶
Bases:
liara.cache._CacheBaseA cache using Redis as the storage backend.
Initialization
- clear()¶
- inspect()¶
- class liara.cache.NullCache¶
Bases:
liara.cache._CacheBaseThe null cache drops all requests and does not cache any data.
This is mostly useful to disable caching in APIs which require a cache instance.
Initialization
- clear() None¶
- inspect() liara.cache.CacheInfo¶