seeren/cache

Manage pool cache items

2.0 2022-01-07 22:28 UTC

This package is auto-updated.

Last update: 2024-04-08 03:05:27 UTC


README

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