gregurco/guzzle-bundle-cache-plugin
最新稳定版本:v3.1.0
Composer 安装命令:
composer require gregurco/guzzle-bundle-cache-plugin
包简介
Cache Plugin for Guzzle Bundle, a PHP HTTP client library and framework for building RESTful web service clients
关键字:
README 文档
README
This plugin integrates cache functionality into Guzzle Bundle, a bundle for building RESTful web service clients.
Requirements
- PHP 7.2 or above
- Guzzle Bundle
- Guzzle Cache middleware
Installation
Using composer:
composer.json
{
"require": {
"gregurco/guzzle-bundle-cache-plugin": "dev-master"
}
}
command line
$ composer require gregurco/guzzle-bundle-cache-plugin
Usage
Enable bundle
Symfony 2.x and 3.x
Plugin will be activated/connected through bundle constructor in app/AppKernel.php, like this:
new EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle([ new Gregurco\Bundle\GuzzleBundleCachePlugin\GuzzleBundleCachePlugin(), ])
Symfony 4
The registration of bundles was changed in Symfony 4 and now you have to change src/Kernel.php to achieve the same functionality.
Find next lines:
foreach ($contents as $class => $envs) { if (isset($envs['all']) || isset($envs[$this->environment])) { yield new $class(); } }
and replace them by:
foreach ($contents as $class => $envs) { if (isset($envs['all']) || isset($envs[$this->environment])) { if ($class === \EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle::class) { yield new $class([ new \Gregurco\Bundle\GuzzleBundleCachePlugin\GuzzleBundleCachePlugin(), ]); } else { yield new $class(); } } }
Basic configuration
# app/config/config.yml eight_points_guzzle: clients: api_payment: base_url: "http://api.domain.tld" # define headers, options # plugin settings plugin: cache: enabled: true
Configuration with specific cache strategy
# app/config/services.yml services: acme.filesystem_cache: class: Doctrine\Common\Cache\FilesystemCache arguments: ['/tmp/'] public: false acme.doctrine_cache_storage: class: Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage arguments: ['@acme.filesystem_cache'] public: false acme.private_cache_strategy: class: Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy arguments: ['@acme.doctrine_cache_storage'] public: false
# app/config/config.yml eight_points_guzzle: clients: api_payment: plugin: cache: enabled: true strategy: "acme.private_cache_strategy"
More information about cache strategies can be found here: Kevinrob/guzzle-cache-middleware
Invalidate cache
# get client $apiPaymentClient = $this->get('eight_points_guzzle.client.api_payment'); # do a request $apiPaymentClient->request('GET', 'ping'); # invalidate cache $event = new InvalidateRequestEvent($apiPaymentClient, 'GET', 'ping'); $this->get('event_dispatcher')->dispatch(GuzzleBundleCacheEvents::INVALIDATE, $event);
License
This middleware is licensed under the MIT License - see the LICENSE file for details
统计信息
- 总下载量: 341.33k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-24