yiisoft/cache-file
File-based cache storage for Yii, implementing PSR-16 simple cache. Stores cached values in files with TTL support, configurable cache directory, and efficient serialization for applications needing persistent, dependency-free caching.
composer require yiisoft/cache-file. The only runtime contract that matters is psr/simple-cache (Psr\SimpleCache\CacheInterface) — there is no Laravel or Yii runtime dependency you need to boot.src/FileCache.php. This package is essentially a single class; the README plus that file is the entire API surface. Confirm the constructor/with* argument names in the exact version you pin, since the 1.x → 2.x line changed how the cache directory and permissions are configured.storage/framework/cache/yiifile, not the file driver's directory), then use it as a black-box PSR-16 store:$cache = new \Yiisoft\Cache\File\FileCache(storage_path('framework/cache/yiifile'));
$cache->set('report.42', $payload, 300);
$payload = $cache->get('report.42');
$this->app->singleton(CacheInterface::class, fn () =>
new \Yiisoft\Cache\File\FileCache(storage_path('framework/cache/yiifile'))
);
Illuminate\Contracts\Cache\Repository. Type-hint CacheInterface, inject FileCache in Laravel, inject an in-memory PSR-16 in tests, and the class never learns about either framework.Psr\SimpleCache\CacheInterface in your application code; let the container choose FileCache in production. This is the only pattern where this package earns its place in a Laravel codebase.Cache:: facade. Register a custom driver via Cache::extend('yiifile', ...) returning an Illuminate\Cache\Repository backed by a Store that delegates to FileCache. Worth it only if multiple developers will expect Cache::remember() ergonomics; otherwise you have written a shim to regain features you deliberately left behind.file/redis driver for framework concerns (sessions, queues, view cache, rate limiting) and use this store for one narrow, explicit concern: long-lived generated artifacts, third-party API response caching, or a shared cache between a Laravel app and a non-Laravel sibling process..../yiifile/{tenant}). File-backed caches degrade badly when a single directory accumulates tens of thousands of entries and multiple writers contend on locks.clear() from a scheduled command or on deploy, and prune by mtime for the rest. Do not rely on inline garbage collection to keep the directory small — its probability-based sweep is a best-effort heuristic, not a policy.FileCache against a sys_get_temp_dir() directory, so serialization and TTL behaviour are covered without slowing the suite.remember/rememberForever, no increment/decrement, no flush prefix scoping. PSR-16 clear() wipes the whole directory. If you find yourself reimplementing those, you probably wanted Cache::store('file').unserialize(). Keep the directory outside the webroot, tighten permissions, and pin allowed_classes behaviour if you are on a shared host.www-data vs. your CLI user is the classic failure: artisan warms the cache, FPM cannot read or overwrite it, and you get permission-denied or silently stale hits. Run php artisan as the same user, or chmod the tree once and verify.ls and recognise a key. When investigating, read the file mtime and contents directly, or temporarily log the key→path mapping. Use a stable key prefix (v2:tenant:) so you can reason about generations.composer.json, review the diff on upgrade, and have a one-line fallback (swap the PSR-16 implementation) ready. Because your code only depends on CacheInterface, that fallback is genuinely cheap — which is the strongest argument for using this package the way described above.How can I help you explore Laravel packages today?