PHP code example of doekenorg / cache-middleware

1. Go to this page and download the library: Download doekenorg/cache-middleware 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/ */

    

doekenorg / cache-middleware example snippets


use DoekeNorg\CacheMiddleware\MiddlewareCachePool;

$regular_psr6_cache_pool = ...; // your current PSR-6 cache pool
$decorator_cache_pool = new MiddlewareCachePool($regular_psr6_cache_pool, ...$middlewares);
//or
$decorator_cache_pool = new MiddlewareCachePool($regular_psr6_cache_pool);
$decorator_cache_pool->addMiddleware(...$middlewares);

use DoekeNorg\CacheMiddleware\MiddlewareGetInterface;
use DoekeNorg\CacheMiddleware\MiddlewareSaveInterface;
use DoekeNorg\CacheMiddleware\MiddlewareDeleteInterface;
use Psr\Cache\CacheItemInterface;

final class ExampleMiddleware implements MiddlewareGetInterface, MiddlewareSaveInterface, MiddlewareDeleteInterface {
    public function processGet(string $key, callable $next): CacheItemInterface {
        $cache_item = $next($key);
        // do something to the cache item
        return $cache_item;
    }
    
    public function processSave(CacheItemInterface $cacheItem, callable $next): bool {
        // do something to the cache item
        return $next($cacheItem);
    }
    
    public function processDelete(string $key, callable $next): bool {
        // perform some action based on the key or the deleted result.
        return $next($key);
    }
}