Download the PHP package peroks/guzzle-file-cache without Composer
On this page you can find all versions of the php package peroks/guzzle-file-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download peroks/guzzle-file-cache
More information about peroks/guzzle-file-cache
Files in peroks/guzzle-file-cache
Package guzzle-file-cache
Short Description A lightweight file cache for Guzzle 7+ implementing the PSR-16 Caching Interface
License MIT
Informations about the package guzzle-file-cache
Simple file caching for the Guzzle http client
A lightweight file cache for Guzzle 7+ implementing the PSR-16 Caching Interface
How to use
<?php
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Peroks\GuzzleFileCache\Cache;
use Peroks\GuzzleFileCache\FileStorage;
function getGuzzleClient( array $options = [] ): Client {
$stack = HandlerStack::create();
$store = new FileStorage( 'your/cache/directory' );
$cache = new Cache( $store );
$stack->push( $cache );
$options['handler'] = $stack;
return new Client( $options );
}
You use an instance of the Peroks\GuzzleFileCache\Cache
class to add
file-caching as a handler (middleware) to the Guzzle http client.
Peroks\GuzzleFileCache\FileStorage
does the real work, implementing the
PSR-16: Common Interface for Caching Libraries.
After you have added caching to the Guzzle http client, there is a new
option for caching: ttl
(time-to-live). The ttl
value is in seconds.
You can set this option for each request sent through the client.
If you omit this option or set ttl
to 0
, the request is not cached.
$response = $client->send( $request, [ 'ttl' => 3600 ] ); // 1 hour caching.
Installing
You need composer to download and install peroks/guzzle-file-cache.
Just run composer require peroks/guzzle-file-cache
in your project.