league/flysystem-cached-adapter
Caching adapter for Flysystem that speeds up filesystem operations by storing metadata (like directory listings and file info) in a cache backend. Reduces repeated calls to slower storage (S3/FTP) and improves performance in read-heavy scenarios.
Storage facade (via league/flysystem-* adapters) and integrates with caching drivers (Redis, Memcached, file cache).Local, S3, Ftp) with minimal boilerplate.
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Adapter\LocalAdapter;
$adapter = new CachedAdapter(
new LocalAdapter('/path/to/storage'),
new \League\Flysystem\Cached\Storage\Psr6CacheStorage(
$cachePool // PSR-6 cache (e.g., Redis)
)
);
Filesystem via service providers or config overrides.cacheInvalidator (e.g., League\Flysystem\Cached\CacheInvalidator) or use Laravel’s cache tags.CacheStorage options) or use size-based pruning.Storage::put)?S3, Database) will we prioritize for caching?Storage facade adapters (e.g., local, s3) with CachedAdapter.CachedAdapter as a singleton or context-bound service.array_key_first).Filesystem::adapter() or custom adapters.local) in a non-critical module.microtime benchmarks).config/filesystems.php to use CachedAdapter for read-heavy disks.'disks' => [
'local' => [
'driver' => 'custom',
'adapter' => CachedAdapter::class,
'source' => storage_path('app'),
'cache' => 'redis',
],
],
s3, ftp).Storage::afterWriting).Storage facade.cache_ttl: 0).| Step | Priority | Dependencies | Owner |
|---|---|---|---|
| Benchmark baseline | High | None | DevOps/TPM |
| POC implementation | High | Cache backend (Redis) | Backend Dev |
| Config updates | Medium | Laravel Filesystem | TPM/Dev |
| Invalidation logic | High | Storage events | Backend Dev |
| Monitoring setup | Low | Prometheus/Grafana | SRE |
Storage::deleteDirectory).league/flysystem and psr/cache for breaking changes.CacheInvalidator or Laravel cache tags.Storage::disk()->has() and Storage::disk()->lastModified() to verify metadata.debugbar or laravel-debugbar to inspect cache storage.file driver) for edge cases where distributed cache is unavailable.memory_get_usage().| Failure Scenario | Impact | Mitigation Strategy |
|---|---|---|
| Cache backend unavailable | Degraded performance | Fallback to non-cached adapter |
| Stale cache (uninvalidated) | Incorrect file metadata | Implement CacheInvalidator or cache tags |
| Cache corruption | Silent data inconsistencies | Validate metadata on read (e.g., checksum) |
| High cache miss ratio | No performance benefit | Adjust TTL or cache strategy |
| PHP/Flysystem version mismatch | Runtime errors | Pin versions in composer.json |
cacheInvalidator->invalidate()).hits / (hits + misses)).How can I help you explore Laravel packages today?