PHP code example of slam / flysystem-local-cache-proxy
1. Go to this page and download the library: Download slam/flysystem-local-cache-proxy library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
slam / flysystem-local-cache-proxy example snippets
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);