Skip to content

Commit 08db915

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

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

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)

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+

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)