slam/flysystem-local-cache-proxy

FlySystem adapter to cache locally the content of files

v0.1.0 2021-12-03 15:24 UTC

This package is auto-updated.

Last update: 2024-04-09 20:07:54 UTC


README

Latest Stable Version Downloads Integrate Code Coverage Type Coverage Infection MSI

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?

  1. league/flysystem-cached-adapter is for Flysystem v1, this package is for Flysystem v2
  2. lustmored/flysystem-v2-simple-cache-adapter caches metadatas, this package focuses on caching file contents