pavlyshyn/cache

0.2.1 2016-08-04 21:49 UTC

This package is auto-updated.

Last update: 2024-10-27 02:23:25 UTC


README

Install

composer require pavlyshyn/cache

Usage

use Pavlyshyn\Cache;
use Pavlyshyn\Cache\Adapter\File;

$adapter = new File(__DIR__ . '/tmp');
$cache = new Cache($adapter);

$cache->set('key', 'value');
var_dump($cache->get('key'));

Methods

$cache->set($key, $value);

$cache->get($key);

$cache->exists($key);

$cache->remove($key);

$cache->clear();

Memcache adapter

use Pavlyshyn\Cache\Adapter\Memcache;

$adapter = new Memcache('127.0.0.1', 11211);

Apc adapter

use Pavlyshyn\Cache\Adapter\Apc;

$adapter = new Apc();

Predis adapter

use Pavlyshyn\Cache\Adapter\Predis;

$adapter = new Predis();

OR

$adapter = new Predis([
    'scheme' => 'tcp',
    'host'   => '10.0.0.1',
    'port'   => 6379,
]);

OR

$adapter = new Predis('tcp://10.0.0.1:6379');

XCache adapter

use Pavlyshyn\Cache\Adapter\XCache;

$adapter = new XCache('admin', '');

Memory adapter

use Pavlyshyn\Cache\Adapter\Memory;

$adapter = new Memory();

Tests

phpunit --bootstrap vendor/autoload.php  tests/Adapter/ApcTest
phpunit --bootstrap vendor/autoload.php  tests/Adapter/MemcacheTest
phpunit --bootstrap vendor/autoload.php  tests/Adapter/XCacheTest
phpunit --bootstrap vendor/autoload.php  tests/Adapter/PredisTest
phpunit --bootstrap vendor/autoload.php  tests/Adapter/MemoryTest
phpunit --bootstrap vendor/autoload.php  tests/Adapter/FileTest