ftembe/cachehandler
最新稳定版本:v1
Composer 安装命令:
composer require ftembe/cachehandler
包简介
The project is a lightweight caching solution that improves performance by storing and retrieving data efficiently. It offers a file-based storage approach with customizable expiration times, automatic removal of expired data, and ensures the cache folder is accessible and writable. Integrating this
README 文档
README
The project is a lightweight caching solution that improves performance by storing and retrieving data efficiently. It offers a file-based storage approach with customizable expiration times, automatic removal of expired data, and ensures the cache folder is accessible and writable. Integrating this caching mechanism enhances application speed and reduces processing time.
Installation
composer require ftembe/cachehandler
Or
git clone https://github.com/FTembe/Cachehandler.git
How to use
<?php
use Ftembe\Cachehandler\Cachehandler;
require 'vendor/autoload.php';
function fetchDataFromApi($endPoint = 'https://jsonplaceholder.typicode.com/photos/')
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_URL, $endPoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if ($e = curl_error($curl))
echo $e;
curl_close($curl);
return $response;
}
/*
You can create a folder to receive temporary data and pass it as a parameter when instantiating the CacheHandler class
eg. $cacheHandler = new Cachehandler('cacheFolder');
*/
$cacheHandler = new Cachehandler();
if ($cacheHandler->getDataLength('photos') != 5000){
$store = $cacheHandler->store('photos', json_decode(fetchDataFromApi()), '1 hour');
}
$getDataLength = $cacheHandler->getDataLength('photos');
$getDataType = $cacheHandler->getDataType('photos');
$get = $cacheHandler->get('photos');
var_dump($get);
var_dump($getDataLength);
var_dump($getDataType);
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-04