cache.storage.factury_fun
On this page
build_storage()
def build_storage(config: CacheConfig) -> BaseStorage
Overview
A match/case factory that constructs the correct BaseStorage
implementation based on config.storage_backend. This is how
CacheManager obtains its _storage attribute — there is no other
call site for this function in the analyzed source, and no public constructor parameter
lets a caller inject a pre-built storage instance directly.
Signature
Returns
Raises
Internal Workflow
A single match config.storage_backend: statement with three case arms plus a wildcard
case _: that raises. No conditional logic beyond the match itself; no logging.
Examples
from zerda.cache.config_cache import CacheConfig, StorageBackend
from zerda.cache.storage import build_storage
# Memory
storage = build_storage(CacheConfig(storage_backend=StorageBackend.MEMORY))
# SQLite (also the default)
storage = build_storage(CacheConfig()) # StorageBackend.SQLITE by default
# Redis — falls back to SQLite internally if unreachable; see RedisStorage
storage = build_storage(CacheConfig(storage_backend=StorageBackend.REDIS))
Complexity
O(1) — a single dispatch plus one backend constructor call (whose own cost varies: Memory
is instant, SQLite performs disk I/O and DDL execution, Redis performs a network
round-trip and possibly falls back to SQLite).
Thread Safety
The function itself holds no state and is safe to call from any thread. The safety of the returned object depends on which backend was built — see each backend's own page.