Skip to content

Configuration Options

Muhammet Şafak edited this page Jun 10, 2026 · 1 revision

Configuration Options

Options are passed to Cache::create() (or a handler constructor) as an associative array. Keys are matched case-insensitively, so prefix, Prefix and PREFIX are the same option. Anything you omit falls back to the default.

$cache = Cache::create(File::class, [
'path' => __DIR__ . '/var/cache',
'prefix' => 'app_',
]);
$cache->getOption('prefix'); // "app_"$cache->getOption('mode', 0640); // 0640 (default returned when unset)$cache->setOptions(['prefix' => 'v2_']); // merge more in; returns $this

Shared option — every handler

OptionTypeDefaultDescription
prefixstringcache_Prepended to every key after validation; scopes clear() on the File and PDO handlers. Set to '' to disable.
OptionTypeDefaultDescription
pathstring(required)Directory the cache files live in. Must exist and be writable.
modeint|null0640chmod() mode per file; null skips chmod().
Cache::create(File::class, [
'path' => __DIR__ . '/var/cache',
'mode' => 0600,
'prefix' => 'app_',
]);
OptionTypeDefaultDescription
dsnstringmysql:host=localhost;dbname=testPDO connection DSN.
usernamestring|nullnullConnection user.
passwordstring|nullnullConnection password.
charsetstringutf8mb4MySQL only (SET NAMES).
collationstringutf8mb4_general_ciMySQL only.
tablestringcacheTable name; must match [A-Za-z0-9_]+.
Cache::create(PDO::class, [
'dsn' => 'pgsql:host=127.0.0.1;dbname=app',
'username' => 'app',
'password' => 'secret',
'table' => 'app_cache',
]);
OptionTypeDefaultDescription
hoststring127.0.0.1Server host.
portint6379Server port.
timeoutint|float0Connection timeout in seconds (0 = unlimited).
passwordstring|nullnullAUTH password; skipped when null.
databaseint|null0Database index to SELECT.
Cache::create(Redis::class, [
'host' => 'redis.internal',
'port' => 6379,
'database' => 3,
'timeout' => 1.5,
]);
OptionTypeDefaultDescription
hoststring127.0.0.1Server host.
portint11211Server port.
weightint1Server weight (Memcached only).
default_ttlint0TTL used when set() gets no TTL. 0 = no expiry.
Cache::create(Memcache::class, [
'host' => 'memcached.internal',
'port' => 11211,
'default_ttl' => 300,
]);

WinCachedeprecated

OptionTypeDefaultDescription
default_ttlint0TTL used when set() gets no TTL. 0 = no expiry.

Notes on types

  • Numeric options are coerced leniently: a numeric string like '6379' is accepted for an integer option. A non-numeric value falls back to the default.
  • path and the PDO table are validated and will throw a CacheException if missing/invalid — see each handler page.

Next steps

  • The Cache Factory — how options are applied and merged.
  • The individual handler pages for the meaning and edge cases of each option.

Clone this wiki locally