fleche.storage.memory

Classes

MemoryBackend

A concrete implementation of Storage that stores values in an in-memory dictionary.

ValueMemory

Mixin that recursively destructures collections on save/load.

CallMemory

Bridges CallStorage with StorageBackend primitives.

Module Contents

class fleche.storage.memory.MemoryBackend[source]

Bases: fleche.storage.base.StorageBackend

A concrete implementation of Storage that stores values in an in-memory dictionary.

storage: dict[fleche.digest.Digest, Any][source]
list() Iterable[fleche.digest.Digest][source]
put(value: Any, key: fleche.digest.Digest) fleche.digest.Digest[source]
get(key: fleche.digest.Digest) Any[source]
_contains(key: fleche.digest.Digest) bool[source]
_evict(key: fleche.digest.Digest) None[source]
class fleche.storage.memory.ValueMemory[source]

Bases: fleche.storage.destructuring.DestructuringMixin, fleche.storage.base.ValueMixin, MemoryBackend

Mixin that recursively destructures collections on save/load.

Place before a ValueMixin in the MRO to add destructuring behavior. Lists, tuples, and dicts are broken apart so each element is stored independently; on load the original structure is reassembled.

Example

>>> from fleche.storage.base import ValueMixin
>>> from fleche.storage.memory import MemoryBackend
>>> @dataclass(frozen=True)
... class MyValueStorage(DestructuringMixin, ValueMixin, MemoryBackend): ...
>>> vm = MyValueStorage(storage={})
>>> key = vm.save([1, [2, 3]])
>>> vm.load(key) == [1, [2, 3]]
True
class fleche.storage.memory.CallMemory[source]

Bases: fleche.storage.base.CallMixin, MemoryBackend

Bridges CallStorage with StorageBackend primitives.

Implements save, load, and query using put and get, deriving the storage key from the call’s lookup key. transform is inherited from CallStorage.

Concrete classes inherit from this and a StorageBackend implementation to get a fully functional call storage.