Skip to content

Commit c8003da

Browse files
committed
Use the new cache plugin factory method
1 parent be18a9e commit c8003da

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"php-http/discovery": "^1.0",
2525
"php-http/client-implementation": "^1.0",
2626
"php-http/client-common": "^1.3",
27-
"php-http/cache-plugin": "^1.2"
27+
"php-http/cache-plugin": "^1.3"
2828
},
2929
"require-dev": {
3030
"phpunit/phpunit": "^4.0 || ^5.5",

Diff for: doc/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ Additional features:
4242
* [Request any Route](request_any_route.md)
4343
* [Customize `php-github-api`](customize.md)
4444
* [Running and writing tests](testing.md)
45+
* [Response caching](caching.md)

Diff for: doc/caching.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Response caching
2+
[Back to the navigation](README.md)
3+
4+
This example uses the PSR6 cache pool [redis-adapter](https://github.com/php-cache/redis-adapter). See http://www.php-cache.com/ for alternatives.
5+
6+
```php
7+
<?php
8+
9+
// This file is generated by Composer
10+
require_once 'vendor/autoload.php';
11+
12+
use Cache\Adapter\Redis\RedisCachePool;
13+
14+
$client = new \Redis();
15+
$client->connect('127.0.0.1', 6379);
16+
// Create a PSR6 cache pool
17+
$pool = new RedisCachePool($client);
18+
19+
$client = new \Github\Client();
20+
$client->addCache($pool);
21+
22+
// Do some request
23+
24+
// Stop using cache
25+
$client->removeCache();
26+
```
27+
28+
Using cache, the client will get cached responses if resources haven't changed since last time,
29+
**without** reaching the `X-Rate-Limit` [imposed by github](http://developer.github.com/v3/#rate-limiting).
30+

Diff for: lib/Github/HttpClient/Builder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ public function addHeaderValue($header, $headerValue)
176176
/**
177177
* Add a cache plugin to cache responses locally.
178178
*
179-
* @param CacheItemPoolInterface $cache
179+
* @param CacheItemPoolInterface $cachePool
180180
* @param array $config
181181
*/
182182
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
183183
{
184-
$this->cachePlugin = new Plugin\CachePlugin($cachePool, $this->streamFactory, $config);
184+
$this->cachePlugin = Plugin\CachePlugin::clientCache($cachePool, $this->streamFactory, $config);
185185
$this->httpClientModified = true;
186186
}
187187

0 commit comments

Comments
 (0)