xnicon/simple-php-cache
Composer 安装命令:
composer require xnicon/simple-php-cache
包简介
Simple PHP cache
README 文档
README
Quick Start
To install Simple PHP Cache, simply:
$ composer require xnicon/php-simple-cache
Code Examples
Example One
require __DIR__ . '/vendor/autoload.php'; use \phpCache\Cache; $c = new Cache(); if(!$c->has("example")) { $c->set("example", 'cache data', 300); // cache result for 5 minutes (300 seconds) } else { echo $c->get("example"); }
Example Two
$example = $c->get("example"); if($example !== false) { echo "Cached: " . $example; $c->remove("example"); // remove from cache } else { echo "Cache not found or expired"; }
Example Three
$c->set("progress", 50, 300); // cache result for 5 minutes (300 seconds) $progress = $c->get("progress", 0); // default return 0 echo "Progress: " . $progress;
Functions
__construct($name, $dir, $ext)
Class constructor
$name- name of the cache (defaultphpcache)$dir- directory where the cache will be stored (default TEMP directory)$ext- extension of the cache file (default.cache)
set($key, $value, $ttl = 0)
Writes data to cache
$key- key of the value$value- value$ttl- Time To Live (in how many seconds value will expire)
get($key, $default = false)
Reads data from cache
$key- key of the value$default- is default value return if value by$keynot found (defaultfalse)- return:
- bool(false) - value not cached or expired
- array - if success
remove($key)
Removes data from cache
$key- key of the value- return:
- bool(false) - key not found
- bool(true) - success
has($key)
Check exists and not is expired cache
$key- key of the value- return:
- bool(false) - not found
- bool(true) - is found
clean()
clean cache file
- return:
- bool(false) - fail
- bool(true) - success
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-27