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
: requiresext-redis
file
: stores cache on diskarray
: non-persistent runtime cache (useful for testing)memory
: memory-efficient LRU cache with adjustable sizeroadrunner-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.