Cache
Kit provides a Laravel-inspired Cache facade for storing and retrieving data with optional TTL (time-to-live) expiration. The cache automatically uses Redis when available, falling back to an in-memory cache when Redis is unavailable.Overview
The cache system is automatically initialized when your server starts - no manual setup required. It tries to connect to Redis first, and if Redis isn’t available, it seamlessly falls back to an in-memory cache.Quick Start
Configuration
The cache uses environment variables for configuration. All are optional with sensible defaults.Example .env
Basic Operations
Storing Items
Retrieving Items
Removing Items
The Remember Pattern
Theremember method retrieves an item from the cache, or stores a default value if it doesn’t exist:
Atomic Counters
Increment and decrement numeric values atomically:Testing
In tests, you can use the in-memory cache implementation directly:Type Safety
The cache works with any type that implementsSerialize and Deserialize:
Redis vs In-Memory
The framework automatically selects the appropriate backend:
- Redis: When
REDIS_URLenvironment variable is set and Redis is accessible - In-Memory: When Redis is not available (development, testing, or Redis failure)