cicnavi / simple-file-cache-php
基于文件的PSR-16简单缓存提供程序。
v2.0.0
2021-08-18 11:28 UTC
Requires
- php: >=7.4
- ext-gmp: *
- ext-json: *
- ext-openssl: *
- psr/simple-cache: ^1.0
Requires (Dev)
- ext-xdebug: *
- phpunit/phpunit: ^9.4
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^3.14
Provides
This package is auto-updated.
Last update: 2024-09-18 20:42:52 UTC
README
cicnavi/simple-file-cache-php
基于文件的PSR-16简单缓存提供程序。
安装
composer require cicnavi/simple-file-cache-php
使用
使用Cicnavi\SimpleFileCache\SimpleFileCache类实例化缓存实例。它可以接受以下参数
- $cacheName (可选/推荐,字符串) - 用于分隔缓存域的缓存名称,默认为'simple-file-cache'
- $storagePath (可选,字符串) - 用于存储缓存文件的可写文件夹路径。如果不提供,将使用默认系统'tmp'文件夹。
- $fileSystemService (可选,Cicnavi\SimpleFileCache\Services\Interfaces\FileSystemServiceInterface) - 用于与文件系统通信的FileSystemServiceInterface实例(默认为Cicnavi\SimpleFileCache\Services\FileSystemService)
使用不同的缓存名称是推荐的做法,用于分隔缓存域。如果您不指定缓存名称,则将使用默认值。请注意,PSR-16包括clear()方法,该方法将清除特定域(特定缓存名称)的整个缓存。
示例
use Cicnavi\SimpleFileCache\SimpleFileCache; $cache = new SimpleFileCache('some-cache-name', '/some/writable/storage/folder'); // Alternatively, instantiate it using defaults... // $cache = new SimpleFileCache('some-cache-name'); // Use specific cache name, but use default system 'tmp' folder // $cache = new SimpleFileCache(); // Use default cache name and default system 'tmp' folder $somethingImportant = 'This string was fetched from API using HTTP request, which is expensive. I\'ll store it in cache for later use so I don\'t have to make another HTTP request for the same thing'; // Use any of the PSR-16 metods to work with cache...: $cache->set('somethingImportant', $somethingImportant); //... later $somethingImportant = $cache->get('somethingImportant');
测试
这将运行phpunit,psalm和phpcs
$ composer run-script test
许可证
MIT