Mixins
Bases: CacheIfMissingMixin
Mixin class which aggregates all mixins from magic_storage.mixins submodule.
Bases: ABC
Source code in magic_storage/mixins/_cache_if_missing.py
cache_if_missing(uid, callback, store_type=StoreType.PICKLE)
#
Store and return object if not present in cache, otherwise load from cache and return.
In case of load failure object cache is recreated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uid |
str
|
Object identifier used to find object in cache. |
required |
callback |
Callable[[], _R]
|
Callback function which can create new object if object is not found in cache |
required |
store_type |
StoreType, optional
|
Determines how object should be stored in cache, by default StoreType.PICKLE |
StoreType.PICKLE
|
Returns:
Type | Description |
---|---|
_R
|
Object loaded from cache OR object created with callback and stored to cache. |
Source code in magic_storage/mixins/_cache_if_missing.py
Last update:
August 5, 2022
Created: August 5, 2022
Created: August 5, 2022