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

1.1 2020-04-23 04:52 UTC

This package is auto-updated.

Last update: 2024-10-23 14:47:32 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
$store = new Godam\Store\FileSystemStore(__DIR__ . '/cache');
// 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 simpler, PSR-16 cache
 */
$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 older, PSR-6 item pool
 */
$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.