GSEGUtils.lazy_disk_cache
- class GSEGUtils.lazy_disk_cache.LazyDiskCache
Bases:
ABC- _MEMMAP_SUFFIX = '.dat'
- __init__(**settings)
- Parameters:
settings (Unpack[LazyDiskCacheKw])
- Return type:
None
- _abc_impl = <_abc._abc_data object>
- _convert_to_memmap()
Allocate (or reopen) the persistent memmap file and switch your live buffer to it, but do not flush or drop the old array.
- Return type:
None
- _convert_to_ndarray()
Pull the memmap entirely into RAM as a plain ndarray.
- Return type:
None
- abstractmethod _describe_buffer()
Return (shape, dtype, in-memory array)
- abstractmethod _describe_shape_dtype()
Return (shape, dtype) without accessing the full array
- abstractmethod _drop_buffer()
Drop the in-memory array (e.g. set to None or similar)
- Return type:
None
- _init_from_config(config)
- Parameters:
config (LazyDiskCacheConfig)
- Return type:
None
- abstractmethod _set_buffer(buf)
Given a memmap, restore it into your object
- disable_caching()
- Return type:
None
- disable_purge()
Disable automatic deletion of the cache file when the object is garbage-collected.
- enable_caching()
- Return type:
None
- enable_purge()
Enable automatic deletion of the cache file when the object is garbage-collected. Registers a new finalizer if needed.
- static ensure_loaded(func)
- load(mode='r+')
Reload the buffer from disk into memory (i.e. make self._mmap your active buffer).
- Parameters:
mode (Literal['r', 'r+', 'w+', 'c'])
- Return type:
None
- offload()
Flush the current buffer to disk, drop the in-RAM array, and mark offloaded.
- Return type:
None
- on_load()
Hook called after loading into memory. Use to cleanup or reinitialize.
- Return type:
None
- on_offload()
Hook called after offloading to disk. Use to prune resources.
- Return type:
None
- class GSEGUtils.lazy_disk_cache.LazyDiskCacheConfig
Bases:
object- __init__(*args, **kwargs)
- Parameters:
__dataclass_self__ (PydanticDataclass)
args (Any)
kwargs (Any)
- Return type:
None
- as_kwargs()
- Return type:
- classmethod from_kwargs(settings)
- Parameters:
settings (LazyDiskCacheKw)
- Return type:
- updated(**overrides)
- Parameters:
overrides (LazyDiskCacheKw)
- Return type:
- class GSEGUtils.lazy_disk_cache.DiskBackedNDArray
Bases:
LazyDiskCache,NDArrayOperatorsMixin- __init__(data, **settings)
- _abc_impl = <_abc._abc_data object>
- _describe_buffer()
Return (shape, dtype, in-memory array)
- _describe_shape_dtype()
Return (shape, dtype) without accessing the full array
- _drop_buffer()
Drop the in-memory array (e.g. set to None or similar)
- Return type:
None
- _set_buffer(buf)
Given a memmap, restore it into your object
- property data
- class GSEGUtils.lazy_disk_cache.DiskBackedStore
Bases:
MutableMapping[str,T],Generic- _DBNDArrayFileExt = '.pkl'
- __init__(*, config=LazyDiskCacheConfig(), factory, value_type=None, validator=None)
- _abc_impl = <_abc._abc_data object>
- add_data_to_store(key, data, *, enable_caching_override=None, automatic_offloading_override=None, purge_disk_on_gc_override=None)
- items() a set-like object providing a view on D's items
- offload(keys=None, pickle_container=False)
Offloads selected entries to disk. When no keys are provided, every cached entry is considered. Items with cache_enabled=False are skipped. When pickle_container is True we pickle the entire container, clear the in-memory reference, and rely on lazy reload the next time the key is accessed.
- _factory: Factory