piotrpress / cacher
此库提供了一种简单的基于文件的缓存解决方案。
v1.2.0
2024-09-16 09:19 UTC
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2024-09-16 09:19:50 UTC
README
此库提供了一种简单的基于文件的缓存解决方案。
安装
$ composer require piotrpress/cacher
使用
require __DIR__ . '/vendor/autoload.php'; use PiotrPress\Cacher; $cache = new Cacher( '.cache', 3600 ); $value = $cache->get( 'hi', function ( $arg1, $arg2 ) { return "$arg1 $arg2"; }, 'Hello', 'world!' ); $cache->clear( 'hi' ); // clear cache for "hi" key $cache->clear(); // clear all cache
您可以使用 php://memory
作为文件来在内存中存储缓存,例如,在开发或测试期间。
Cacher 以秒为单位的过期时间作为第二个参数。默认情况下,它设置为 -1
,这意味着缓存永远不会过期。如果提供 0
的值,则每次调用都会清除缓存。
要求
支持 PHP >= 7.4
版本。