Skip to content

royopa/guzzle-cache-middleware

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

guzzle-cache-middleware

Latest Stable Version Total Downloads License Build Status
Scrutinizer Code Quality SensioLabsInsight

A HTTP Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. This project is under development but it's already functional.

composer require kevinrob/guzzle-cache-middleware:~0.4

Why?

Performance. It's very common to do some HTTP calls to an API for rendering a page and it takes times to do it.

How?

With a simple Middleware added at the top of the HandlerStack of Guzzle6.

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Kevinrob\GuzzleCache;

// Create default HandlerStack
$stack = HandlerStack::create();

// Add this middleware to the top with `push`
$stack->push(CacheMiddleware::getMiddleware(), 'cache');

// Initialize the client with the handler option
$client = new Client(['handler' => $stack]);

You can use a custom Cache with:

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Kevinrob\GuzzleCache;
use Doctrine\Common\Cache;

// Create default HandlerStack
$stack = HandlerStack::create();

// Add this middleware to the top with `push`
$stack->push(CacheMiddleware::getMiddleware(new PrivateCache(new FileCache('/tmp/')), 'cache');

// Initialize the client with the handler option
$client = new Client(['handler' => $stack]);

About

A HTTP Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%