Cache
Cache ManagerLink
The sierra.internal.cache
module provides a simple file‑based cache for speeding up repeated operations (e.g., sideloader scans, compilation outputs).
Using the CacheManager
sierra.internal.cache
Link
ClassesLink
CompressionType
Link
CacheEntry
dataclass
Link
CacheEntry(
key: str,
value: typing.Any,
created_at: float,
expires_at: typing.Optional[float] = None,
compression: CompressionType = CompressionType.NONE,
size_bytes: int = 0,
access_count: int = 0,
last_accessed: float = 0.0,
)
Represents a cache entry with metadata.
AttributesLink
compression
class-attribute
instance-attribute
Linkcompression: CompressionType = CompressionType.NONE
CacheManager
Link
CacheManager(
cache_dir: typing.Optional[pathlib.Path] = None,
max_memory_entries: int = 1000,
cleanup_interval: float = 3600,
auto_cleanup: bool = True,
)
A full-featured cache manager with SQLite-backed persistence, TTL expiration, auto-cleanup, compression, and efficient key enumeration.
Features: - SQLite-backed metadata storage for fast key enumeration - Separate file storage for large values - Memory cache for frequently accessed items - TTL support with automatic cleanup - Compression support (gzip) - Thread-safe operations - Access statistics tracking - Atomic operations
Initialize the CacheManager.
PARAMETER | DESCRIPTION |
---|---|
cache_dir
|
Directory for cache storage. If None, uses OS-appropriate location. |
max_memory_entries
|
Maximum number of entries to keep in memory cache.
TYPE:
|
cleanup_interval
|
Interval in seconds between automatic cleanup runs.
TYPE:
|
auto_cleanup
|
Whether to automatically clean up expired entries.
TYPE:
|
FunctionsLink
set
Linkset(
key: str,
value: typing.Any,
ttl: typing.Optional[float] = None,
persist: bool = True,
compress: bool = False,
) -> None
Store a value in the cache.
PARAMETER | DESCRIPTION |
---|---|
key
|
Cache key.
TYPE:
|
value
|
Value to cache.
TYPE:
|
ttl
|
Time to live in seconds.
TYPE:
|
persist
|
Whether to persist to disk (default: True).
TYPE:
|
compress
|
Whether to compress the value.
TYPE:
|
get
LinkRetrieve a value from the cache.
PARAMETER | DESCRIPTION |
---|---|
key
|
Cache key.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any or None
|
The cached value or None if not found/expired. |
exists
Link
delete
Linkdelete(key: str) -> None
Delete a cache entry.
PARAMETER | DESCRIPTION |
---|---|
key
|
Cache key.
TYPE:
|
keys
Link
cleanup
Linkcleanup() -> int
Manually clean up expired entries.
RETURNS | DESCRIPTION |
---|---|
int
|
Number of entries removed. |
get_entry_info
Link