Skip to main content
Lyger provides a powerful in-memory caching system that persists across requests in Always-Alive mode. The cache is backed by Rust FFI for maximum performance, making it a Redis alternative without external dependencies.

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:
Cache locks are simple mutex implementations. For distributed systems, use a dedicated lock service like Redis or a database-based lock.

Custom TTL

Set default TTL or override per operation:

Real-World Examples

API Rate Limiting

Query Result Caching

Session Management

Performance Tips

Pre-populate cache on application startup:
Use consistent, hierarchical naming:
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