cheese44 / cheesecache
A request scoped cache library for PHP with the goal to make caching consistent and maintainable.
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
A request scoped cache library for PHP with the goal to make caching consistent and maintainable.
Best used for caching function and query results that are called multiple times during a request and are unlikely to change
Installation
Package is available on Packagist, you can install it using Composer.
composer require cheese44/cheesecache
Usage
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; } }