Skip to content

Commit 24e4b08

Browse files
committed
Use PSR6 cache
1 parent 9717e8e commit 24e4b08

File tree

10 files changed

+17
-504
lines changed

10 files changed

+17
-504
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ From `$client` object, you can access to all GitHub.
6969
// This file is generated by Composer
7070
require_once 'vendor/autoload.php';
7171

72+
use Cache\Adapter\Redis\RedisCachePool;
73+
74+
$client = new \Redis();
75+
$client->connect('127.0.0.1', 6379);
76+
// Create a PSR6 cache pool
77+
$pool = new RedisCachePool($client);
78+
7279
$client = new \Github\Client();
73-
$client->useCache();
74-
75-
// Or select directly which cache you want to use
76-
$client->useCache(
77-
// Built in one, or any cache implementing this interface:
78-
// Github\HttpClient\Cache\CacheInterface
79-
new \Github\HttpClient\Cache\FilesystemCache('/tmp/github-api-cache')
80-
);
80+
$client->useCache($pool);
8181
```
8282

8383
Using cache, the client will get cached responses if resources haven't changed since last time,

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
],
1919
"require": {
2020
"php": "^5.5|^7.0",
21+
"psr/http-message": "^1.0",
22+
"psr/cache": "^1.0",
2123
"php-http/httplug": "^1.0",
2224
"php-http/discovery": "^1.0",
2325
"php-http/client-implementation": "^1.0",
24-
"php-http/client-common": "^1.1"
26+
"php-http/client-common": "^1.1",
27+
"php-http/cache-plugin": "^1.0"
2528
},
2629
"require-dev": {
2730
"phpunit/phpunit": "~4.0",

lib/Github/Client.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
use Github\Api\ApiInterface;
66
use Github\Exception\InvalidArgumentException;
77
use Github\Exception\BadMethodCallException;
8-
use Github\HttpClient\Cache\CacheInterface;
98
use Github\HttpClient\Plugin\Authentication;
10-
use Github\HttpClient\Plugin\Cache;
119
use Github\HttpClient\Plugin\GithubExceptionThrower;
1210
use Github\HttpClient\Plugin\History;
1311
use Github\HttpClient\Plugin\PathPrepend;
@@ -19,6 +17,7 @@
1917
use Http\Discovery\MessageFactoryDiscovery;
2018
use Http\Discovery\UriFactoryDiscovery;
2119
use Http\Message\MessageFactory;
20+
use Psr\Cache\CacheItemPoolInterface;
2221

2322
/**
2423
* Simple yet very cool PHP GitHub client.
@@ -375,19 +374,12 @@ public function addHeaders(array $headers)
375374
}
376375

377376
/**
378-
* @param bool|CacheInterface $cache
377+
* @param CacheItemPoolInterface $cache
379378
*/
380-
public function useCache($cache = true)
379+
public function useCache(CacheItemPoolInterface $cachePool)
381380
{
382-
$this->removePlugin(Cache::class);
383-
if ($cache !== false) {
384-
if ($cache instanceof CacheInterface) {
385-
$plugin = new Cache($cache);
386-
} else {
387-
$plugin = new Cache();
388-
}
389-
$this->addPlugin($plugin);
390-
}
381+
$this->removePlugin(Plugin\CachePlugin::class);
382+
$this->addPlugin(new Plugin\CachePlugin($cachePool));
391383
}
392384

393385
/**

lib/Github/HttpClient/Cache/CacheInterface.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

lib/Github/HttpClient/Cache/FilesystemCache.php

Lines changed: 0 additions & 85 deletions
This file was deleted.

lib/Github/HttpClient/Cache/GaufretteCache.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

lib/Github/HttpClient/Cache/ResponseSerializer.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)