Docs LATEST

Cache Configuration

Configure cache drivers, prefixes, and storage paths.

Configuration

Cache configuration lives in config/cache.php, overridable in user/config/cache.php.

Full Configuration Example #

return [
    // Default driver: 'file', 'redis', or 'apcu'
    'default' => env('CACHE_DRIVER', 'file'),
    
    // Key prefix (prevents collisions with other apps)
    'prefix' => env('CACHE_PREFIX', 'velvet'),
    
    'drivers' => [
        // File-based cache (default)
        'file' => [
            'path' => storage_path('cache'),
        ],
        
        // Redis cache
        'redis' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'port' => env('REDIS_PORT', 6379),
            'password' => env('REDIS_PASSWORD'),
            'database' => env('REDIS_DB', 0),
            'timeout' => 1.5,
            'persistent' => false,
        ],
        
        // APCu in-memory cache
        'apcu' => [
            'prefix' => env('CACHE_PREFIX', 'velvet'),
        ],
    ],
];

Configuration Options #

default #

Which driver to use. Options: file, redis, apcu.

prefix #

String prefix for all cache keys. Prevents key collisions when sharing a Redis instance or APCu pool with other applications.

drivers.file.path #

Directory where file cache stores entries. Defaults to storage/cache.

drivers.redis.* #

Option Default Description
host 127.0.0.1 Redis server hostname
port 6379 Redis server port
password null Redis AUTH password
database 0 Redis database number (0-15)
timeout 1.5 Connection timeout in seconds
persistent false Use persistent connections

drivers.apcu.prefix #

APCu doesn't support databases, so the prefix is essential for isolation.

Environment Variables #

Common variables to set in your environment:

CACHE_DRIVER=redis
CACHE_PREFIX=myapp
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=secret
REDIS_DB=0

Multi-Tenancy Behavior #

When tenancy is enabled:

  • Prefix is automatically extended: velvet becomes velvet:tenant_123
  • File path resolves under the tenant's storage: storage/tenants/123/cache

No configuration changes needed-isolation is automatic.

Choosing a Driver #

Driver When to Use
file Default, works everywhere, no dependencies
redis Multiple servers, high traffic, need persistence
apcu Single server, maximum speed, volatile is okay