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.ABC
Interface for key-value caches.
- abstract 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).
- abstract put(key: bytes, value: object) bool ¶
Put a value into the cache using the provided key.
- Parameters:
key – The key under which
value
will be stored.value – A pickable Python object to be stored.
- Returns:
True
if the value was added to the cache,False
if it was already cached.
- abstract get(key: bytes) Optional[object] ¶
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.
- abstract clear() None ¶
Clear the contents of the cache.
Added in version 2.5.
- abstract 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._CacheBase
A
Cache
implementation 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._CacheBase
A
Cache
implementation 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._CacheBase
An in-memory
Cache
implementation.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._CacheBase
A cache using Redis as the storage backend.
Initialization
- clear()¶
- inspect()¶
- class liara.cache.NullCache¶
Bases:
liara.cache._CacheBase
The 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 ¶