PHP code example of clickalicious / cachingmiddleware
1. Go to this page and download the library: Download clickalicious/cachingmiddleware 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/ */
clickalicious / cachingmiddleware example snippets
/**
* Fill queue for running "Caching Middleware"
*
* @param \Psr\Http\Message\ServerRequestInterface $request Request (PSR) to process
* @param \Psr\Http\Message\ResponseInterface $response Response (PSR) to use
* @param callable $next Next middleware in stack
*
* @return \Psr\Http\Message\ResponseInterface A PSR compatible response
*/
$queue[] = function (Request $request, Response $response, callable $next) {
// Create cache item factory
$cacheItemFactory = function ($key) {
return new CacheItem($key);
};
// Create cache item key factory
$cacheItemKeyFactory = function (Request $request) {
static $key = null;
if (null === $key) {
$uri = $request->getUri();
$slugify = new Slugify();
$key = $slugify->slugify(trim($uri->getPath(), '/').($uri->getQuery() ? '?'.$uri->getQuery() : ''));
}
return $key;
};
// Get cache
$cachingMiddleWare = new Clickalicious\Caching\Middleware\Cache(
new CacheItemPool('Filesystem'),
$cacheItemFactory,
$cacheItemKeyFactory
);
return $cachingMiddleWare($request, $response, $next);
};
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.