Data Cache#
Data caching functionality for MDA files.
This module provides caching capabilities to improve performance when loading and processing MDA files.
|
LRU cache for MDA file data to improve performance and manage memory usage. |
|
Cached file data with metadata. |
Get the global data cache instance. |
- class mdaviz.data_cache.CachedFileData(file_path: str, metadata: dict[str, ~typing.Any], scan_dict: dict[str, ~typing.Any], first_pos: int, first_det: int, pv_list: list, file_name: str, folder_path: str, access_time: float = <factory>, size_bytes: int = 0)[source]#
Cached file data with metadata.
- class mdaviz.data_cache.DataCache(*args: Any, **kwargs: Any)[source]#
LRU cache for MDA file data to improve performance and manage memory usage.
This cache stores loaded MDA file data in memory and automatically evicts least recently used entries when memory limits are exceeded.
- Attributes:
max_size_mb (float): Maximum cache size in megabytes max_entries (int): Maximum number of cached entries enable_compression (bool): Whether to compress cached data max_memory_mb (float): Maximum system memory usage in megabytes
- _check_memory_usage() float [source]#
Check current memory usage and trigger cleanup if needed.
- Returns:
float: Current memory usage in MB
- _evict_lru() bool [source]#
Evict the least recently used entry from the cache.
- Returns:
bool: True if an entry was evicted, False if cache is empty
- _load_without_caching(path_obj: Path) CachedFileData | None [source]#
Load file data without caching it (for large files or high memory usage).
- Parameters:
path_obj (Path): Path object to the file
- Returns:
CachedFileData or None: Loaded data (not cached)
- cache_eviction#
alias of
str
- cache_hit#
alias of
str
- cache_miss#
alias of
str
- get(file_path: str) CachedFileData | None [source]#
Get cached data for a file.
- Parameters:
file_path (str): Path to the file
- Returns:
CachedFileData or None: Cached data if available, None otherwise
- get_or_load(file_path: str) CachedFileData | None [source]#
Get cached data or load and cache it if not available.
- Parameters:
file_path (str): Path to the file
- Returns:
CachedFileData or None: Data from cache or newly loaded
- get_stats() dict[str, Any] [source]#
Get cache statistics.
- Returns:
dict: Cache statistics including size, entry count, hit rate, etc.
- load_and_cache(file_path: str) CachedFileData | None [source]#
Load file data and cache it.
- Parameters:
file_path (str): Path to the file to load
- Returns:
CachedFileData or None: Loaded and cached data
- memory_warning#
alias of
float
- put(file_path: str, cached_data: CachedFileData) None [source]#
Store data in the cache.
- Parameters:
file_path (str): Path to the file cached_data (CachedFileData): Data to cache
- remove(file_path: str) bool [source]#
Remove a file from the cache.
- Parameters:
file_path (str): Path to the file to remove
- Returns:
bool: True if the file was in the cache, False otherwise