File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Storages
2+
3+ Storages keep cached values and provide the per-key locks used by the decorator to prevent dog-piling.
4+
5+ Built-in storages:
6+ - ` TTLMapStorage ` : synchronous in-memory storage with TTL expiration and LRU eviction.
7+ - ` TTLMapAsyncStorage ` : asynchronous counterpart for ` async def ` functions.
8+
9+ Usage:
10+
11+ ``` python
12+ from datetime import timedelta
13+ from cachium import cache
14+ from cachium.storages.ttl_map import TTLMapStorage
15+
16+ @cache (storage = TTLMapStorage.create_with(max_size = 1000 , ttl = timedelta(minutes = 5 )))
17+ def get_value (key : str ) -> str :
18+ return f " value: { key} "
19+ ```
20+
21+ Important details:
22+ - ` cache ` expects a storage factory, not a storage instance.
23+ - The factory is called once at decoration time, giving each decorated function its own storage.
24+ - Use ` TTLMapStorage ` for regular functions and ` TTLMapAsyncStorage ` for async functions.
25+ - ` max_size ` limits entry count; ` ttl ` controls age-based expiration. Use ` ttl=None ` to disable age-based expiration.
26+ - Built-in storages are process-local. Use a custom storage backend for shared multi-process or cross-machine caching.
27+
28+ Full reference below.
29+
30+ ::: cachium.storages._ abc.Result
31+
32+ ---
33+
34+ ::: cachium.storages._ abc.BaseStorage
35+
36+ ---
37+
38+ ::: cachium.storages._ abc.BaseAsyncStorage
39+
40+ ---
41+
42+ ::: cachium.storages.ttl_map.TTLMapStorage
43+
44+ ---
45+
46+ ::: cachium.storages.ttl_map.TTLMapAsyncStorage
You can’t perform that action at this time.
0 commit comments