File tree 3 files changed +33
-2
lines changed
3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -42,3 +42,4 @@ Additional features:
42
42
* [ Request any Route] ( request_any_route.md )
43
43
* [ Customize ` php-github-api ` ] ( customize.md )
44
44
* [ Running and writing tests] ( testing.md )
45
+ * [ Response caching] ( caching.md )
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change @@ -176,12 +176,12 @@ public function addHeaderValue($header, $headerValue)
176
176
/**
177
177
* Add a cache plugin to cache responses locally.
178
178
*
179
- * @param CacheItemPoolInterface $cache
179
+ * @param CacheItemPoolInterface $cachePool
180
180
* @param array $config
181
181
*/
182
182
public function addCache (CacheItemPoolInterface $ cachePool , array $ config = [])
183
183
{
184
- $ this ->cachePlugin = new Plugin \CachePlugin ($ cachePool , $ this ->streamFactory , $ config );
184
+ $ this ->cachePlugin = Plugin \CachePlugin:: clientCache ($ cachePool , $ this ->streamFactory , $ config );
185
185
$ this ->httpClientModified = true ;
186
186
}
187
187
You can’t perform that action at this time.
0 commit comments