Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ From `$client` object, you can access to all GitHub.
// This file is generated by Composer
require_once 'vendor/autoload.php';

use Cache\Adapter\Redis\RedisCachePool;

$client = new \Redis();
$client->connect('127.0.0.1', 6379);
// Create a PSR6 cache pool
$pool = new RedisCachePool($client);

$client = new \Github\Client();
$client->useCache();

// Or select directly which cache you want to use
$client->useCache(
// Built in one, or any cache implementing this interface:
// Github\HttpClient\Cache\CacheInterface
new \Github\HttpClient\Cache\FilesystemCache('/tmp/github-api-cache')
);
$client->addCache($pool);

// Do some request

// Stop using cache
$client->removeCache();
```

Using cache, the client will get cached responses if resources haven't changed since last time,
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
}
],
"require": {
"php": "^5.5|^7.0",
"php": "^5.5 || ^7.0",
"psr/http-message": "^1.0",
"psr/cache": "^1.0",
"php-http/httplug": "^1.0",
"php-http/discovery": "^1.0",
"php-http/client-implementation": "^1.0",
"php-http/client-common": "^1.1"
"php-http/client-common": "^1.1",
"php-http/cache-plugin": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"php-http/guzzle6-adapter": "~1.0",
"guzzlehttp/psr7": "^1.2",
"sllh/php-cs-fixer-styleci-bridge": "~1.3"
},
"suggest": {
"knplabs/gaufrette": "Needed for optional Gaufrette cache"
},
"autoload": {
"psr-4": { "Github\\": "lib/Github/" }
},
Expand Down
27 changes: 14 additions & 13 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use Github\Api\ApiInterface;
use Github\Exception\InvalidArgumentException;
use Github\Exception\BadMethodCallException;
use Github\HttpClient\Cache\CacheInterface;
use Github\HttpClient\Plugin\Authentication;
use Github\HttpClient\Plugin\Cache;
use Github\HttpClient\Plugin\GithubExceptionThrower;
use Github\HttpClient\Plugin\History;
use Github\HttpClient\Plugin\PathPrepend;
Expand All @@ -19,6 +17,7 @@
use Http\Discovery\MessageFactoryDiscovery;
use Http\Discovery\UriFactoryDiscovery;
use Http\Message\MessageFactory;
use Psr\Cache\CacheItemPoolInterface;

/**
* Simple yet very cool PHP GitHub client.
Expand Down Expand Up @@ -375,19 +374,21 @@ public function addHeaders(array $headers)
}

/**
* @param bool|CacheInterface $cache
* Add a cache plugin to cache responses locally.
* @param CacheItemPoolInterface $cache
*/
public function useCache($cache = true)
public function addCache(CacheItemPoolInterface $cachePool)
{
$this->removePlugin(Cache::class);
if ($cache !== false) {
if ($cache instanceof CacheInterface) {
$plugin = new Cache($cache);
} else {
$plugin = new Cache();
}
$this->addPlugin($plugin);
}
$this->removeCache();
$this->addPlugin(new Plugin\CachePlugin($cachePool));
}

/**
* Remove the cache plugin
*/
public function removeCache()
{
$this->removePlugin(Plugin\CachePlugin::class);
}

/**
Expand Down
51 changes: 0 additions & 51 deletions lib/Github/HttpClient/Cache/CacheInterface.php

This file was deleted.

85 changes: 0 additions & 85 deletions lib/Github/HttpClient/Cache/FilesystemCache.php

This file was deleted.

71 changes: 0 additions & 71 deletions lib/Github/HttpClient/Cache/GaufretteCache.php

This file was deleted.

61 changes: 0 additions & 61 deletions lib/Github/HttpClient/Cache/ResponseSerializer.php

This file was deleted.

Loading