mesavolt/simple-cache
最新稳定版本:v2.2.0
Composer 安装命令:
composer require mesavolt/simple-cache
包简介
Simple cache service.
README 文档
README
Simple cache system based on Symfony's Cache component. Will always return a value, fresh or from cache, depending on TTL.
Installation
composer require mesavolt/simple-cache
Usage
<?php use Mesavolt\SimpleCache; $cache = new SimpleCache(sys_get_temp_dir()); $ttl = 10; // values expire after 10 seconds // use the cache for the 1st, the callable is executed, a fresh value is cached and returned $value1 = $cache->get('key', function () { return time(); }, $ttl); // use the cache again before TTL has passed. // the callable is *not* executed again, the previously cached value is returned $value2 = $cache->get('key', function () { return time(); }, $ttl); assert($value2 === $value1); // true because TTL hasn't expired // sleep 20 seconds, this is longer that our TTL of 10 seconds sleep(20); // use the cache for the 3rd time, TTL has expired so a new fresh value is cached and returned $value3 = $cache->get('key', function () { return time(); }); assert($value3 !== $value1); // true because `sleep(20)` expired the TTL // so the callable has been executed // and a fresh value has been returned (and cached)
统计信息
- 总下载量: 2.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-06