|
1 | 1 | # Cache System Developer Guide |
2 | 2 |
|
3 | 3 | **Audience**: Developers integrating with or extending the cache system |
4 | | -**Last Updated**: November 2025 (Issue #336) |
| 4 | +**Last Updated**: December 2025 (Issue #469) |
5 | 5 |
|
6 | 6 | --- |
7 | 7 |
|
@@ -61,6 +61,44 @@ cache_adapter.set_market_data( |
61 | 61 | ) |
62 | 62 | ``` |
63 | 63 |
|
| 64 | +### Using UnifiedBrokerCache (Issue #469) |
| 65 | + |
| 66 | +For broker state caching (account, positions, orders) with database-first architecture: |
| 67 | + |
| 68 | +```python |
| 69 | +from src.data_sources.cache import unified_broker_cache |
| 70 | + |
| 71 | +# Get cached account (fetches if stale, returns from DB) |
| 72 | +account = unified_broker_cache.get_account( |
| 73 | + account_id="paper_main", |
| 74 | + fetcher=lambda: alpaca_monitor.get_account_status(), |
| 75 | + max_age_seconds=60 |
| 76 | +) |
| 77 | + |
| 78 | +# Get cached positions |
| 79 | +positions = unified_broker_cache.get_positions( |
| 80 | + account_id="paper_main", |
| 81 | + fetcher=lambda: alpaca_monitor.get_positions() |
| 82 | +) |
| 83 | + |
| 84 | +# Store position snapshots for historical tracking |
| 85 | +unified_broker_cache.store_position_snapshot("paper_main", positions) |
| 86 | + |
| 87 | +# Audit display events |
| 88 | +unified_broker_cache.audit_display( |
| 89 | + display_type="portfolio", |
| 90 | + data=positions, |
| 91 | + cache_source="cached", |
| 92 | + cache_age_seconds=30.5 |
| 93 | +) |
| 94 | + |
| 95 | +# Get cache info |
| 96 | +info = unified_broker_cache.get_cache_info("paper_main") |
| 97 | +print(f"Account cache: {info['cache_entries'].get('account', {})}") |
| 98 | +``` |
| 99 | + |
| 100 | +See [Database-First Caching Design](../design/469-database-first-caching.md) for architecture details. |
| 101 | + |
64 | 102 | --- |
65 | 103 |
|
66 | 104 | ## API Reference |
|
0 commit comments