Skip to main content

Cache Configuration (config/cache.php)

The cache.php config file defines which caching drivers your application can use. Beauty Framework supports a variety of drivers including Redis, file-based, in-memory, and RoadRunner KV.

๐Ÿ”ง Default Driverโ€‹

'default' => env('CACHE_DRIVER', 'redis'),

You can switch drivers via the CACHE_DRIVER env variable.

๐Ÿ“ฆ Supported Driversโ€‹

  • redis: requires ext-redis
  • file: stores cache on disk
  • array: non-persistent runtime cache (useful for testing)
  • memory: memory-efficient LRU cache with adjustable size
  • roadrunner-kv: uses RR's KV plugin

๐Ÿš€ Redis Exampleโ€‹

'redis' => [
'driver' => 'redis',
'host' => env('REDIS_HOST', '127.0.0.1'),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
'prefix' => env('REDIS_CACHE_PREFIX', 'beauty:cache:'),
]

๐Ÿงช Usage Exampleโ€‹

use Psr\SimpleCache\CacheInterface;

$cache = container()->get(CacheInterface::class);

$cache->set('key', 'value', 3600);
$value = $cache->get('key');

You can configure multiple stores and use them dynamically within your application.