dev-master
9999999-dev https://github.com/andreacardelli/pitbullcachePhp Cache System
MIT
The Requires
- php >=5.3.0
by Yuri Bacciarini
by Andrea Cardelli
file cache php redis memcached
Php Cache System
PitBullCache is a fast and simple PHP Cache library with the minimum functionalities needed that abstracts different cache mechanisms. It is easy to use and easy to implement with new cache mechanism (MemCache,...)., (*1)
With PitBullCache you can speed up web sites by caching any type of data: variables, queries or even full HTML pages., (*2)
Currently the cache systems abstracted by PitBullCache are:, (*3)
Implemented methods are: - Fetch key - Store key - Delete key - cleanUpExpired (useful jsut for file system), (*4)
PitBullCache supports composer, just add the packagist dependency:, (*5)
{ "require": { "andreacardelli/pitbullcache": "dev-master" } }
We can use any type of cache, here an example with "file" type for caching full HTML page, third parameters contains configuration used by each low level storage (file: directory, redis: standard config for predis\client, S3: key and secret), (*6)
Define your cache (multiple cache for different purposes are allowed), (*7)
Pitbull_Cache::Register("file","Pitbull_Filesystem_Cache","/pitbullcache.cache/"); $_cache = Pitbull_Cache::Create("file");
define your unique key, (*8)
$idpagecache = md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
retrieve the cached value of your key if it exists and if it is still valid otherwise you get false, (*9)
if ($page=$_cache->fetch($idpagecache)) { echo $page; exit(); }
and for storing keys..., (*10)
// caching full html $page for 1 day (86400 seconds) $_cache->store($idpagecache,$page,86400);
(optional) for files sytem cleaning and S3 we added a class to be called with a batch job (cron) for other type of cache storage it just returns the number of cached active objects, (*11)
$_cache->cleanUpExpired('array'); // or 'json' to get back number of deleted items
Php Cache System
MIT
file cache php redis memcached