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.
Use composer to install these available packages:
$ composer install slam/flysystem-local-cache-proxy
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);
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