Spaces:
Running
on
Zero
Running
on
Zero
File size: 2,000 Bytes
76897aa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
"""Caching module for Portfolio Intelligence Platform.
This module provides production-ready caching infrastructure with:
- Hybrid caching (Redis primary, in-memory fallback)
- Domain-specific TTL strategies for financial data
- Event-driven cache invalidation
- Cache warming capabilities
- Comprehensive monitoring and statistics
Example:
Basic usage with HybridCache:
>>> from backend.caching import HybridCache, FinancialDataCacheManager
>>> from backend.config import settings
>>>
>>> cache = HybridCache(
... redis_url=settings.upstash_redis_url,
... redis_token=settings.upstash_redis_token,
... )
>>> manager = FinancialDataCacheManager(cache)
>>>
>>> # Cache market data
>>> manager.cache_market_data("AAPL", {"price": 150.00, "volume": 1000000})
>>>
>>> # Retrieve cached data
>>> data = manager.get_market_data("AAPL")
>>>
>>> # Get statistics
>>> stats = manager.get_stats()
>>> print(f"Hit rate: {stats.hit_rate:.2f}%")
"""
from backend.caching.decorators import (
cached,
cached_async,
cache_invalidate,
)
from backend.caching.factory import (
CacheFactory,
get_cache,
get_cache_manager,
cache,
cache_manager,
)
from backend.caching.redis_cache import (
CacheBackend,
CacheDataType,
CacheInvalidationManager,
CacheKey,
CacheStats,
FinancialDataCacheManager,
HybridCache,
InMemoryCache,
PortfolioCachingStrategy,
TTLStrategy,
)
__all__ = [
# Core classes
"HybridCache",
"InMemoryCache",
"CacheBackend",
"CacheDataType",
"CacheStats",
"CacheKey",
"TTLStrategy",
"PortfolioCachingStrategy",
"CacheInvalidationManager",
"FinancialDataCacheManager",
# Factory and convenience functions
"CacheFactory",
"get_cache",
"get_cache_manager",
# Global instances
"cache",
"cache_manager",
# Decorators
"cached",
"cached_async",
"cache_invalidate",
]
|