Cache System
Learn about SoulCache's intelligent caching layer
Cache System
The Cache System provides high-performance, intelligent caching for your data.
Core Concepts
Cache Entries
Each cached item is stored as a QueryEntry:
Cache Status
Entries have a status indicating freshness:
| Status | Description |
|---|---|
fresh | Data is current |
stale | Data may be outdated |
expired | Data has expired |
invalidated | Data needs refresh |
Query Record State
| State | Description |
|---|---|
idle | Initial state |
pending | Currently fetching |
success | Data available |
error | Fetch failed |
fetching | Background refetch |
stale | Data is stale |
invalidated | Marked for refresh |
destroyed | Entry removed |
Usage
Basic Operations
With Options
Features
Automatic Garbage Collection
Old entries are automatically removed:
Dependency Tracking
Cache tracks dependencies between entries:
Version Conflict Detection
Prevents stale overwrites:
Observer Integration
Cache automatically tracks observers:
Performance
| Operation | Time | Space |
|---|---|---|
| Get | O(1) | O(1) |
| Set | O(1) | O(1) |
| Delete | O(1) | O(1) |
| Clear | O(n) | O(1) |
Best Practices
- Set appropriate stale time - Balance freshness vs performance
- Use dependency tracking - Automatically invalidate related data
- Monitor observer count - Prevent memory leaks
- Leverage garbage collection - Let the cache clean up automatically