Skip to content

Latest commit

 

History

History
35 lines (28 loc) · 689 Bytes

basic-usage-psr6-cachepool.md

File metadata and controls

35 lines (28 loc) · 689 Bytes

Basic Usage - Psr6 Cache Pool

Get an element from cache (using Factory...)

<?php
$pool = \ByJG\Cache\Factory::createMemcachedPool();
$item = $pool->getItem('mykey');
if (!$item->isHit()) {
    // Do the operations will be cached
    // ....
    // And set variable '$value'
    $value = "...";
    $item->set($value);
    $item->expiresAfter(3600);

    $pool->save($item);
}
return $item->get();

Clear an element from cache

<?php
$pool = \ByJG\Cache\Factory::createMemcachedPool();
$pool->deleteItem('mykey');

Create an Element from PSR-16 Interface:

<?php
$pool = new \ByJG\Cache\Psr6\CachePool(new \ByJG\Cache\Psr16\RedisCacheEngine());