DevCraft Документации
EnglishGuides

PSR-6 file cache v1.1.0

FileCachePool: namespaced keys, TTL, clearNamespace, on-disk format.

Introduction

From 1.1.0 the package ships a filesystem PSR-6 pool: Devcraft\Cache\FileCachePool. It implements Psr\Cache\CacheItemPoolInterface without Symfony Cache — files plus psr/cache only.

Prerequisites

Walkthrough

Create a pool

The second argument is the default TTL. null or 0 means no expiry until the item sets its own.

use Devcraft\Cache\FileCachePool;

$pool = new FileCachePool(sys_get_temp_dir() . '/devtools-cache', defaultTtlSeconds: 3600);

Write and read

Keys may contain / — stored as a subdirectory (Translation/dict…/Translation/dict.cache).

$item = $pool->getItem('Translation/dict');
$item->set(['hello' => 'world']);
$pool->save($item);

$hit = $pool->getItem('Translation/dict');
$value = $hit->isHit() ? $hit->get() : null;

Clear a namespace

clearNamespace() is a DevTools extension (not PSR-6): deletes every key under {prefix}/.

$pool->clearNamespace('Translation');

Full example

use Devcraft\Cache\FileCachePool;

$pool = new FileCachePool('/path/to/cache', defaultTtlSeconds: 3600);

$item = $pool->getItem('Translation/dict');
$item->set(['hello' => 'world']);
$pool->save($item);

$hit = $pool->getItem('Translation/dict');
if ($hit->isHit()) {
    $value = $hit->get();
}

$pool->clearNamespace('Translation'); // DevTools extension (not in PSR-6)

Keys and storage

RuleDetails
Allowedletters, digits, / as namespace separator
Forbidden{}()\@: and ..
File path{baseDir}/{key}.cache
EnvelopeJSON { "e": expiryUnix|null, "f": "j"|"s", "v": value }

Format j is a JSON value; s is serialize + base64 for non-JSON data.

DevCraft Admin

In DevCraft Admin, CacheControl is a thin facade: setCache($type, $name, $data) → key {type}/{name}FileCachePool. Prefer CacheControl::pool() for new code.

На этой странице