BaseCache
Cache interface for read-optimized storage. All cache adapters (Memory, Redis, etc.) implement this contract.
See Cache Adapters for concrete adapter configuration.
Initialize Cache with Connection/Adapter details
Source code in src/protean/port/cache.py
9 10 11 12 13 14 15 16 17 18 19 | |
register_projection
register_projection(projection_cls)
Registers a projection object for data serialization and de-serialization
Source code in src/protean/port/cache.py
21 22 23 24 | |
ping
abstractmethod
ping()
Healthcheck to verify cache is active and accessible
Source code in src/protean/port/cache.py
26 27 28 | |
get_connection
abstractmethod
get_connection()
Get the connection object for the cache
Source code in src/protean/port/cache.py
30 31 32 | |
add
abstractmethod
add(projection: BaseProjection, ttl: Optional[Union[int, float]] = None) -> None
Add projection record to cache
KEY: Projection ID
Value: Projection Data (derived from to_dict())
TTL is in seconds. If not specified explicitly in method call, it can be picked up from broker configuration. In the absence of configuration, it can be defaulted to an optimum value, say 300 seconds.
| PARAMETER | DESCRIPTION |
|---|---|
projection
|
Projection Instance containing data
TYPE:
|
ttl
|
Timeout in seconds. Defaults to None.
TYPE:
|
Source code in src/protean/port/cache.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
get
abstractmethod
get(key)
Retrieve data by key
Source code in src/protean/port/cache.py
52 53 54 | |
get_all
abstractmethod
get_all(key_pattern, last_position=0, size=25)
Retrieve data by key pattern
Source code in src/protean/port/cache.py
56 57 58 | |
count
abstractmethod
count(key_pattern)
Retrieve count of data by key pattern
Source code in src/protean/port/cache.py
60 61 62 | |
remove
abstractmethod
remove(projection)
Remove a cache record by projection object
Source code in src/protean/port/cache.py
64 65 66 | |
remove_by_key
abstractmethod
remove_by_key(key)
Remove a cache record by key
Source code in src/protean/port/cache.py
68 69 70 | |
remove_by_key_pattern
abstractmethod
remove_by_key_pattern(key_pattern)
Remove a cache record by key pattern
Source code in src/protean/port/cache.py
72 73 74 | |
flush_all
abstractmethod
flush_all()
Remove all entries in Cache
Source code in src/protean/port/cache.py
76 77 78 | |
set_ttl
abstractmethod
set_ttl(key, ttl)
Set a TTL explicitly on a key
Source code in src/protean/port/cache.py
80 81 82 | |
get_ttl
abstractmethod
get_ttl(key)
Get the TTL set on a key
Source code in src/protean/port/cache.py
84 85 86 | |