slam / flysystem-local-cache-proxy
FlySystem adapter to cache locally the content of files
Fund package maintenance!
Slamdunk
paypal.me/filippotessarotto
Requires
- php: >=8.0
- league/flysystem: ^2.3.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.3.2
- infection/infection: ^0.25.3
- league/flysystem-adapter-test-utilities: ^2.3.2
- malukenho/mcbumpface: ^1.1.5
- phpunit/phpunit: ^9.5.10
- vimeo/psalm: ^4.13.1
This package is auto-updated.
Last update: 2024-11-09 21:32:32 UTC
README
Save to local disk a copy of written and read files to speed up next reads.
Keep local disk cache small by clearing unfrequently accessed files.
Installation
Use composer to install these available packages:
$ composer install slam/flysystem-local-cache-proxy
Usage
use SlamFlysystem\LocalCache\LocalCacheProxyAdapter; use League\Flysystem\AwsS3V3\AwsS3V3Adapter; $adapter = new LocalCacheProxyAdapter( new AwsS3V3Adapter(/* ... */), __DIR__ . '/tmp/flysystem-cache' ); // The FilesystemOperator $filesystem = new \League\Flysystem\Filesystem($adapter); // Upload a file, with stream $handle = fopen('robots.txt', 'r'); $filesystem->writeStream('robots.txt', $handle); fclose($handle); // robots.txt is now present both on Aws and locally // Read the file: no actual hit on Aws // Each read/readStream refreshes the cache timestamp $handle = $filesystem->readStream('robots.txt'); echo stream_get_contents('robots.txt', $handle); fclose($handle); // Clear infrequently used files to save disk space $adapter->clearCacheOlderThan((new DateTime)->modify('-1 week')); // Manually keep fresh a file you know it gets accessed frequently anyway $adapter->touch('robots.txt', new DateTime);
What about the other packages?
league/flysystem-cached-adapter
is for Flysystem v1, this package is for Flysystem v2lustmored/flysystem-v2-simple-cache-adapter
caches metadatas, this package focuses on caching file contents