Last active
January 23, 2020 15:57
-
-
Save holabene/6471423 to your computer and use it in GitHub Desktop.
Guzzle cache that actually works..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Caching to filesystem using ZendCache | |
* Cache as much as possible, very convenient for dev (default ttl = 3600) | |
*/ | |
use Guzzle\Http\Client; | |
use Guzzle\Plugin\Cache\CachePlugin; | |
use Guzzle\Plugin\Cache\SkipRevalidation; | |
use Guzzle\Plugin\Cache\DefaultCacheStorage; | |
use Guzzle\Cache\CacheAdapterFactory; | |
use Zend\Cache\Storage\Adapter\Filesystem as FilesystemCache; | |
$client = new Client('http://api.example.com'); | |
$storage = new FilesystemCache(['cacheDir' => 'some_path']); | |
$cachePlugin = new CachePlugin([ | |
'storage' => new DefaultCacheStorage(CacheAdapterFactory::fromCache($storage)), | |
'revalidation' => new SkipRevalidation, | |
]); | |
$client->addSubscriber($cachePlugin); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment