Guzzle Cache
Component ID
2823851
Component name
Guzzle Cache
Component type
module
Maintenance status
Development status
Component security advisory coverage
covered
Downloads
3127
Component created
Component changed
Component body
Provides a Drupal cache backend for Kevinrob/guzzle-cache-middleware.
Usage
use GuzzleHttpClient;
use GuzzleHttpHandlerStack;
use KevinrobGuzzleCacheCacheMiddleware;
use KevinrobGuzzleCacheStrategyPrivateCacheStrategy;
use Drupalguzzle_cacheDrupalGuzzleCache;
// Create default HandlerStack
$stack = HandlerStack::create();
// Create a Drupal Guzzle cache.
$cache = new DrupalGuzzleCache();
// Push the cache to the stack.
$stack->push(
new CacheMiddleware(
new PrivateCacheStrategy($cache)
),
'cache'
);
// Initialize the client with the handler option
$client = new Client(['handler' => $stack]);
// Fetch the URI cached if available.
$response = $client->request('GET', 'http://www.example.com/');
