sec_interp.core.data_cache module
Cache system for SecInterp data.
Provides a hash-based caching mechanism for geological and topographic data.
- class sec_interp.core.data_cache.DataCache(default_ttl: int = 3600)
Bases:
ICacheServiceMemory-based cache service for storing processed profile data.
Implements ICacheService. Supports categorized buckets (‘topo’, ‘geol’, ‘struct’, ‘drill’), Time-To-Live (TTL) expiration, and arbitrary metadata (e.g., for LOD tracking).
- DEFAULT_TTL_SECONDS = 3600
- __init__(default_ttl: int = 3600) None
Initialize the data cache.
- Parameters:
default_ttl – Default Time-To-Live in seconds for new entries.
- clear() None
Clear all entries across all cache buckets.
- get(bucket: str, key: str) Any | None
Retrieve data from a specific cache bucket if not expired.
- Parameters:
bucket – Name of the cache category (e.g., ‘topo’).
key – Unique hash key for the entry.
- Returns:
The cached data if valid and found, else None.
- get_cache_key(params: dict[str, Any]) str
Generate a unique MD5 hash key from input parameters.
- Parameters:
params – Dictionary of parameters to hash.
- Returns:
The generated MD5 hash string.
- get_cache_size() dict[str, int]
Get the number of entries in each bucket.
- Returns:
Dictionary mapping bucket names to entry counts.
- get_metadata(bucket: str, key: str) dict[str, Any] | None
Retrieve the metadata associated with a cached entry.
- Parameters:
bucket – Name of the cache category.
key – Unique hash key for the entry.
- Returns:
Metadata dictionary if found, else None.
- invalidate(bucket: str | None = None, key: str | None = None) None
Remove entries from the cache selectively or entirely.
- Parameters:
bucket – Optional name of the bucket to invalidate.
key – Optional specific entry key to remove within the bucket.
- set(bucket: str, key: str, data: Any, metadata: dict | None = None) None
Store data in a specific cache bucket with optional metadata.
- Parameters:
bucket – Name of the cache category.
key – Unique hash key for the entry.
data – The data object to be cached.
metadata – Optional dictionary for TTL or Level of Detail information.