cheese44 / cheesecache
一个用于PHP的请求范围缓存库,旨在使缓存一致且易于维护。
v0.8-stable
2016-07-23 09:29 UTC
Requires
- php: >=5.3
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-20 22:33:11 UTC
README
一个用于PHP的请求范围缓存库,旨在使缓存一致且易于维护。
最佳用于缓存在请求期间多次调用且不太可能改变的功能和查询结果
安装
该包可在Packagist上找到,您可以使用Composer进行安装。
composer require cheese44/cheesecache
用法
use cheeseCache\app; class Test { /** * cheeseCache does all the work for you * * you don't have to clutter your code with checking, setting and reading the cache yourself */ public function cacheSum($a, $b) { $cache = cheeseCache\app\cacheProvider::getCache(); $sum = $cache->cache( array($a, $b), function() use($a, $b) { return $a + $b; }); return $sum; } /** * of course cheeseCache still gives you the possibility to manually access these functionalities */ public function cacheSum_Explicit($a, $b) { $cache = cheeseCache\app\cacheProvider::getCache(); if($cache->isCacheSet(array($a, $b))): return $cache->geCacheValue(array($a, $b)); endif; $sum = $a + $b; $cache->cache( array($a, $b), $sum ); return $sum; } }