PHP code example of mikespub / micheh-psr7-cache
1. Go to this page and download the library: Download mikespub/micheh-psr7-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/ */
mikespub / micheh-psr7-cache example snippets
/** @var \Psr\Http\Message\ResponseInterface $response */
$util = new \Micheh\Cache\CacheUtil();
$response = $util->withCache($response);
/** @var \Psr\Http\Message\ResponseInterface $response */
$util = new \Micheh\Cache\CacheUtil();
$response = $util->withCache($response);
$response = $util->withETag($response, 'my-etag');
$response = $util->withLastModified($response, new \DateTime());
/** @var \Psr\Http\Message\RequestInterface $request */
/** @var \Psr\Http\Message\ResponseInterface $response */
$util = new \Micheh\Cache\CacheUtil();
$response = $util->withCache($response);
$response = $util->withETag($response, 'my-etag');
$response = $util->withLastModified($response, new \DateTime());
if ($util->isNotModified($request, $response)) {
return $response->withStatus(304);
}
// create the body of the response
/** @var \Psr\Http\Message\RequestInterface $request */
$util = new \Micheh\Cache\CacheUtil();
if (!$util->hasStateValidator($request)) {
return $response->withStatus(428);
}
/** @var \Psr\Http\Message\RequestInterface $request */
/** @var \Psr\Http\Message\ResponseInterface $response */
$util = new \Micheh\Cache\CacheUtil();
if (!$util->hasStateValidator($request)) {
return $response->withStatus(428);
}
$eTag = 'my-etag'
$lastModified = new \DateTime();
if (!$util->hasCurrentState($request, $eTag, $lastModified)) {
return $response->withStatus(412);
}
// process the request