Basic Usage
The Cache class provides a simple API for storing and retrieving data in memory.Storing Data
Retrieving Data
Removing Data
Rust FFI Cache
For maximum performance, Lyger uses Rust FFI for cache operations when available. This provides near-native speed for cache operations.The Rust FFI cache provides 10-100x faster performance compared to PHP arrays or file-based caching. Perfect for high-throughput applications.
Advanced Features
Remember Pattern
Cache data with a callback that generates the value if not found:Increment & Decrement
Atomic counter operations:Cache Locking
Prevent race conditions with cache locks:Custom TTL
Set default TTL or override per operation:Real-World Examples
API Rate Limiting
Query Result Caching
Session Management
Performance Tips
Cache Warming
Cache Warming
Pre-populate cache on application startup:
Cache Keys
Cache Keys
Use consistent, hierarchical naming:
TTL Strategy
TTL Strategy
Set appropriate TTL based on data volatility:
Comparison with Redis
For distributed applications across multiple servers, use Redis. For single-server Always-Alive applications, Lyger’s cache is faster and simpler.
Next Steps
Events
Learn about event broadcasting
Jobs & Queues
Background job processing