PHP code example of rtheunissen / guzzle-cache-handler
1. Go to this page and download the library: Download rtheunissen/guzzle-cache-handler 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/ */
rtheunissen / guzzle-cache-handler example snippets
use Concat\Http\Handler\CacheHandler;
use Doctrine\Common\Cache\FilesystemCache;
use GuzzleHttp\Client;
// Basic directory cache example
$cacheProvider = new FilesystemCache(__DIR__ . '/cache');
// Guzzle will determine an appropriate default handler if `null` is given.
$defaultHandler = null;
// Create a cache handler with a given cache provider and default handler.
$handler = new CacheHandler($cacheProvider, $defaultHandler, [
/**
* @var array HTTP methods that should be cached.
*/
'methods' => ['GET', 'HEAD', 'OPTIONS'],
/**
* @var integer Time in seconds to cache a response for.
*/
'expire' => 60,
/**
* @var callable Accepts a request and returns true if it should be cached.
*/
'filter' => null,
]);
// Use a PSR-3 compliant logger to log when bundles are stored or fetched.
$handler->setLogger($logger);
// Create a Guzzle 6/7 client, passing the cache handler as 'handler'.
$client = new Client([
'handler' => $handler
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.