PHP code example of dadapas / cache
1. Go to this page and download the library: Download dadapas/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/ */
dadapas / cache example snippets
use Dadapas\Cache\CacheItemPool;
use Dadapas\Cache\CacheItem;
use Dadapas\Cache\FileCacheAdapter;
// Declarations
$adapter = new FileCacheAdapter(__DIR__."/cache"); // cache adapter
$pool = new CacheItemPool($adapter); // pool
$key = "mykey";
$cacheItem = new CacheItem($key); // cache item
// Set the cache value
$cacheItem->set("cache value");
$cacheItem->expiresAfter(3600); // cache will live in 1 hour
$pool->save($cache); // Save the cache
// ...
// Get cache by key null if key not exist
$cacheItem = $pool->getItem($key);
// get the cache value null if expires or non exist key
$cacheItem->get();
// To get the key
$cacheItem->getKey();
// Set the exact expiration date
// This data will expire in 1st january 2023
$cacheItem->expiresAt(new DateTime("2023-01-01"));
//