cache/filesystem-adapter
A PSR-6 cache adapter for Laravel/PHP using Flysystem to store cache files in a filesystem. Store, retrieve, and manage cache efficiently with filesystem-backed persistence. Supports tagging, hierarchy, and easy configuration via setFolder(). Ideal for Laravel applications needing scalable caching s...
Start by installing the package via Composer: composer require cache/filesystem-adapter. Then set up a basic filesystem-based cache pool using Flysystem’s local adapter—ideal for small-to-medium applications or local development environments where APCu or Redis aren’t available or overkill. The simplest working example:
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Cache\Adapter\Filesystem\FilesystemCachePool;
$filesystem = new Filesystem(new Local(sys_get_temp_dir()));
$pool = new FilesystemCachePool($filesystem);
Store and fetch values like any PSR-6 implementation: $pool->getItem('key')->set('value')->expiresAfter(3600);.
phpunit.xml <php> block for isolated test environments, ensuring tests don’t interfere with each other.CacheManager) to abstract configuration—especially useful when swapping adapters (e.g., filesystem ↔ Redis) in config/cache.php.->tag(['user:123', 'posts'])) when building admin panels or multi-entity caches where a subset needs clearing.$pool->setFolder('runtime/cache') to keep cache files in a non-public, writable path—avoiding web-root exposure.addItem, deleteItem). Prefer for read-heavy or low-concurrency workloads.clear() to wipe all items under the pool’s folder—careful when using setFolder() with overlapping paths across multiple pools.filemtime for expiration—ensure your server’s filesystem supports sub-second precision if using short TTLs (< 1s).runtime/cache/ (or your custom folder) directly—each item maps to a .cache file, and tag groups are stored in subdirectories like tag/.symfony/cache with FilesystemAdapter for better support and features (e.g., caching PSR-16 and PSR-6 side-by-side).How can I help you explore Laravel packages today?