A symple cache library. Implements different adapters that you can use and change easily by a manager or similar.
It is best installed it through packagist
by including
desarrolla2/cache
in your project composer.json require:
"require": {
// ...
"desarrolla2/cache": "dev-master"
}
You can also download it from [Github] (https://github.com/desarrolla2/Cache), but no autoloader is provided so you'll need to register it with your own PSR-0 compatible autoloader.
<?php
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\NotCache;
$cache = new Cache(new NotCache());
$cache->set('key', 'myKeyValue', 3600);
// later ...
echo $cache->get('key');
Use it if you will not implement any cache adapter is an adapter that will serve to fool the test environments.
Use it if you will you have dont have other cache system available in your system or if you like to do your code more portable.
<?php
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\File;
$cacheDir = '/tmp';
$adapter = new File($cacheDir);
$adapter->setOption('ttl', 3600);
$cache = new Cache($adapter);
Use it if you will you have APC cache available in your system.
<?php
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Apc;
$adapter = new Apc();
$adapter->setOption('ttl', 3600);
$cache = new Cache($adapter);
Use it if you will you have mongodb available in your system.
<?php
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Mongo;
$server = 'mongodb://localhost:27017';
$adapter = new Mongo($ server);
$adapter->setOption('ttl', 3600);
$cache = new Cache($adapter);
This library implements other adapters as soon as possible, feel free to send new adapters if you think it appropriate.
This can be a list of pending tasks.
- Cleanning cache
- MemcachedAdapter
- Other Adapters
You can contact with me on @desarrolla2.