bookking3000 / guzzcache
用于存储REST-APIs的Guzzle HTTP响应的In-File JSON-Cache
v1.0.2
2022-02-15 08:48 UTC
Requires
- ext-json: *
- guzzlehttp/guzzle: ^7.0
- maxakawizard/json-collection-parser: ^1.8
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-22 16:46:28 UTC
README
用于存储REST-APIs的Guzzle HTTP响应的In-File JSON-Cache
安装
使用composer安装
composer require bookking3000/guzzcache
自动加载
请包含以下内容来自动加载类
require_once __DIR__.'/vendor/bookking3000/guzzcache/autoload.php';
用法
//Initialize Json-File for Caching.
$jsonCache = new JsonCache();
$jsonCache->setCachePath($this->cachePath);
//Initialize GuzzCache and set the Cache to the Cache initialized before.
$guzzCache = new GuzzCache();
$guzzCache->setCache($jsonCache);
//If your request was already sent, this method will retrieve it from the local in-File Cache
$content = $guzzCache->httpQuery("https://jsonplaceholder.typicode.com/todos/1", "GET");
生命周期
默认生命周期为30天/2592000秒。
您可以通过以下方式更改它
$jsonCache = new JsonCache();
$jsonCache->setCachePath($this->cachePath);
$jsonCache->setLifetime(60); //60 Seconds
要禁用生命周期,将生命周期设置为0。
$jsonCache = new JsonCache();
$jsonCache->setCachePath($this->cachePath);
$jsonCache->setLifetime(0);
调试
将调试设置为true,将记录所有请求。默认情况下,只有具有非2xx响应状态码的请求会被记录。
日志存储在库目录中的logs文件夹中。
$guzzCache = new GuzzCache();
$guzzCache->setDebug(true);
变更日志
2022-02-15
- 添加了缓存过期时间