mirror of
https://github.com/shadoll/moma.git
synced 2026-08-28 11:33:25 +00:00
feat(cache): Implement unified caching subsystem with decorators, strategies, and management
- Added core caching functionality with `Cache` class supporting in-memory and file-based caching. - Introduced `CacheManager` for high-level cache operations and statistics. - Created various cache key generation strategies: `FilepathMethodStrategy`, `APIRequestStrategy`, `SimpleKeyStrategy`, and `CustomStrategy`. - Developed decorators for easy method caching: `cached`, `cached_method`, `cached_api`, and `cached_property`. - Implemented type definitions for cache entries and statistics. - Added comprehensive tests for cache operations, strategies, and decorators to ensure functionality and backward compatibility.
This commit is contained in:
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
"""Type definitions for cache subsystem."""
|
||||
|
||||
from typing import TypedDict, Any, Dict
|
||||
|
||||
|
||||
class CacheEntry(TypedDict):
|
||||
"""Type definition for cache entry structure.
|
||||
|
||||
Attributes:
|
||||
value: The cached value (any JSON-serializable type)
|
||||
expires: Unix timestamp when entry expires
|
||||
"""
|
||||
value: Any
|
||||
expires: float
|
||||
|
||||
|
||||
class CacheStats(TypedDict):
|
||||
"""Type definition for cache statistics.
|
||||
|
||||
Attributes:
|
||||
cache_dir: Path to cache directory
|
||||
subdirs: Statistics for each subdirectory
|
||||
total_files: Total number of cache files
|
||||
total_size_bytes: Total size in bytes
|
||||
total_size_mb: Total size in megabytes
|
||||
memory_cache_entries: Number of entries in memory cache
|
||||
"""
|
||||
cache_dir: str
|
||||
subdirs: Dict[str, Dict[str, Any]]
|
||||
total_files: int
|
||||
total_size_bytes: int
|
||||
total_size_mb: float
|
||||
memory_cache_entries: int
|
||||
Reference in New Issue
Block a user