Skip to content

seeren/cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Seeren\Cache

Build Require Coverage Download Codacy Badge Version

Cache items in pool

Installation

Seeren\Cache is a PSR-6 cache interfaces implementation

composer require seeren/cache

Seeren\Cache\StreamCacheItemPool

Store item in stream pool

use Seeren\Cache\Pool\StreamCacheItemPool;

$pool = new StreamCacheItemPool();

$item = $pool
    ->getItem('foo')
    ->expiresAfter(5);

if (!$item->isHit()) {
    $item->set("item data");
    $pool->save();
}

$data = $item->get();

By default, cache folder is in /var/cache

project/
└─ var/
   └─ log/

Seeren\Cache\CacheItem

Use item for manage Last-Modified with the extra method last

$response = $response
    ->withHeader("ETag", $eTag)
    ->withHeader("Last-Modified", $item->last())
    ->withHeader("Cache-Control", "public, max-age=" . $timeToLive)
    ->withHeader("Expires", $item->last(true));

Passing true at last add the timeToLive to the lastSave timestamp


License

This project is licensed under the MIT License