| """ |
| Aggressive Caching Shield β Multi-Layer API Protection for Free RPC Tiers |
| |
| Protects free tier RPC API keys (Helius, QuickNode, Alchemy) from |
| exhaustion by frontend traffic. Enforces cache-first architecture: |
| |
| 1. RpcCacheClient β Redis L2 + in-memory L1 cache with TTL tiers |
| 2. RpcRateLimiter β Token bucket rate limiting per provider |
| 3. RpcBatcher β JSON-RPC batch request grouper (reduces call count) |
| 4. HistoryDepthController β Caps default query depth, gates deep scans |
| 5. WsClientManager β Connection-pooled Redis pub/sub for live streams |
| |
| All modules fall back gracefully if Redis is unavailable. |
| |
| Usage: |
| from app.caching_shield import ( |
| get_rpc_cache, |
| get_rate_limiter, |
| get_ws_manager, |
| get_history_controller, |
| ) |
| |
| # Cache-first RPC query |
| cache = get_rpc_cache() |
| result = await cache.get_balance("SoL...") |
| |
| # Rate-limited via token bucket |
| limiter = get_rate_limiter() |
| allowed, wait = await limiter.acquire("helius", "getBalance") |
| if not allowed: |
| raise HTTPException(429, f"Rate limited, retry in {wait:.1f}s") |
| |
| # Broadcast to WebSocket stream |
| ws = get_ws_manager() |
| await ws.broadcast_scan({"token": "SoL...", "safety_score": 85}) |
| |
| # Clamp query depth |
| hdc = get_history_controller() |
| limit = hdc.clamp_limit(100, is_deep_scan=True) |
| """ |
|
|
| from app.caching_shield.api_registry import ( |
| PROVIDER_REGISTRY, |
| ApiKey, |
| KeyPool, |
| ProviderConfig, |
| UnifiedApiManager, |
| get_api_manager, |
| ) |
| from app.caching_shield.batcher import ( |
| BATCH_WINDOW_MS, |
| MAX_BATCH_SIZE, |
| BatchRequest, |
| BatchResult, |
| RpcBatcher, |
| ) |
| from app.caching_shield.funding_tracer import ( |
| FundingTrace, |
| trace_funding_source, |
| ) |
| from app.caching_shield.history_depth import ( |
| DEFAULT_DEPTH, |
| MAX_DEPTH, |
| MAX_PAGINATED, |
| HistoryDepthController, |
| get_history_controller, |
| ) |
| from app.caching_shield.rate_limiter import ( |
| PROVIDER_LIMITS, |
| ProviderLimit, |
| RpcRateLimiter, |
| get_rate_limiter, |
| ) |
| from app.caching_shield.rpc_cache import ( |
| TTL_TABLE, |
| CacheStats, |
| RpcCacheClient, |
| get_rpc_cache, |
| ) |
| from app.caching_shield.solana_tracker import ( |
| SolanaTrackerClient, |
| get_solana_tracker, |
| ) |
| from app.caching_shield.tool_data import ( |
| ToolData, |
| td, |
| ) |
| from app.caching_shield.unified_layer import ( |
| ToolResult, |
| UnifiedDataLayer, |
| get_data_layer, |
| ) |
| from app.caching_shield.ws_broadcaster import ( |
| CHANNEL_ALERTS, |
| CHANNEL_PRICES, |
| CHANNEL_SCANS, |
| CHANNEL_TOKENS, |
| WsClientManager, |
| get_ws_manager, |
| ) |
|
|
| __all__ = [ |
| "PROVIDER_REGISTRY", |
| "ApiKey", |
| "KeyPool", |
| "ProviderConfig", |
| "UnifiedApiManager", |
| "get_api_manager", |
| "FundingTrace", |
| "trace_funding_source", |
| "ToolData", |
| "td", |
| "ToolResult", |
| "UnifiedDataLayer", |
| "get_data_layer", |
| ] |
|
|