Simple PSR-6/PSR-16 cache implementations >= PHP 5.3.

1.0 2017-01-26 04:01 UTC

README

Simple PSR-6/PSR-16 cache implementations PHP >= 5.3.

Godam: गोदाम (Warehouse)

Build status Code Coverage Latest Version Downloads PHP Version License

SensioLabsInsight

Install

composer require vaibhavpandeyvpz/godam

Usage

<?php

/**
 * @desc Create an instance of Godam\StoreInterface
 */
$store = new Godam\Store\MemoryStore();
// Or
$memcache = new Memcache();
$memcache->connect('localhost', 11211);
$store = new Godam\Store\MemcacheStore($memcache);
// Or
$redis = new Predis\Client('tcp://127.0.0.1:6379');
$store = new Godam\Store\PredisStore($redis);
// Or
$redis = new Redis();
$redis->connect('localhost', 6379);
$store = new Godam\Store\RedisStore($redis);

/*
 * @desc Using the simple cache (PSR-16)
 */
$cache = new Godam\Cache($store);
$cache->set('somekey', 'somevalue', 3600 /** ttl in second(s), can be null */);
$value = $cache->get('somekey');
$cache->delete('somekey');

/*
 * @desc Or the cache item pool (PSR-6)
 */
$cache = new Godam\CacheItemPool($store);
$item = $cache->getItem('somekey');
if ($item->isHit()) {
    $value = $item->get();
} else {
    $item->set('somevalue');
    $cache->save($item);
}
$cache->deleteItem('somekey');

License

See LICENSE.md file.