1. Go to this page and download the library: Download nanoblocktech/psr-cache library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nanoblocktech / psr-cache example snippets
use \Luminova\Psr\Cache\CachePool;
use \Luminova\Psr\Cache\CacheItem;
$pool = CachePool::withFileCache('my_cache', 'my_cache_folder');
// Set a cache item
$item = $pool->getItem('cache_key');
$item->set('This is my cache data');
$pool->save($item);
// Get a cache item
$data = $pool->getItem('cache_key')->get();
// Check if the cache item exists
if (!$item->isHit()) {
$data = databaseLoadData();
$item->expiresAfter(new DateInterval('PT1H'));
$item->set($data);
$pool->save($item);
} else {
// Data exists in the cache, use it directly
$data = $item->get();
}
// Retrieve the key of the cache item.
$item->getKey(): string;
// Retrieve the value of the cache item.
$item->get(): mixed;
// Check if the cache item is a hit.
$item->isHit(): bool;
// Set the value of the cache item.
$item->set(mixed $value): static;
// Set the expiration time of the cache item.
$item->expiresAt(?DateTimeInterface $expiration): static;
// Set the expiration time relative to the current time.
$item->expiresAfter(int|DateInterval|null $time): static;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.