slam / flysystem-local-cache-proxy
FlySystem 适配器,用于在本地缓存文件内容
v0.1.0
2021-12-03 15:24 UTC
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-09-09 21:11:25 UTC
README
将写入和读取的文件副本保存到本地磁盘,以加速下一次读取。
通过清除不常访问的文件来保持本地磁盘缓存小。
安装
使用 composer 安装这些可用的包
$ 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
适用于 Flysystem v1,此包适用于 Flysystem v2lustmored/flysystem-v2-simple-cache-adapter
缓存元数据,此包专注于缓存文件内容