Skip to content

Commit eb1702c

Browse files
committed
Add simple way to configure cache dir
1 parent 34c1dff commit eb1702c

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

lib/Github/Client.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class Client
5555

5656
'api_limit' => 5000,
5757
'api_version' => 'beta',
58+
59+
'cache_dir' => null
5860
);
5961

6062
/**

lib/Github/HttpClient/Cache/FilesystemCache.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class FilesystemCache implements CacheInterface
1212
protected $path;
1313

1414
/**
15-
* @param null|string $path
15+
* @param string $path
1616
*/
17-
public function __construct($path = null)
17+
public function __construct($path)
1818
{
19-
$this->path = $path ?: sys_get_temp_dir().DIRECTORY_SEPARATOR.'php-github-api-cache';
19+
$this->path = $path;
2020
}
2121

2222
/**

lib/Github/HttpClient/CachedHttpClient.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33
namespace Github\HttpClient;
44

55
use Buzz\Client\ClientInterface;
6-
use Buzz\Message\MessageInterface;
7-
use Buzz\Message\RequestInterface;
8-
use Buzz\Listener\ListenerInterface;
96

10-
use Github\Exception\ErrorException;
11-
use Github\Exception\RuntimeException;
12-
use Github\HttpClient\Listener\ErrorListener;
13-
use Github\HttpClient\Message\Request;
14-
use Github\HttpClient\Message\Response;
157
use Github\HttpClient\Cache\CacheInterface;
168
use Github\HttpClient\Cache\FilesystemCache;
179

@@ -24,15 +16,26 @@
2416
*/
2517
class CachedHttpClient extends HttpClient
2618
{
19+
/**
20+
* @var CacheInterface
21+
*/
2722
protected $cache;
2823

24+
/**
25+
* @param array $options
26+
* @param null|ClientInterface $client
27+
* @param null|CacheInterface $cache
28+
*/
2929
public function __construct(array $options = array(), ClientInterface $client = null, CacheInterface $cache = null)
3030
{
3131
parent::__construct($options, $client);
3232

33-
$this->cache = $cache ?: new FilesystemCache;
33+
$this->cache = $cache ?: new FilesystemCache($this->options['cache_dir'] ?: sys_get_temp_dir().DIRECTORY_SEPARATOR.'php-github-api-cache');
3434
}
3535

36+
/**
37+
* {@inheritdoc}
38+
*/
3639
public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array())
3740
{
3841
$response = parent::request($path, $parameters, $httpMethod, $headers);
@@ -50,10 +53,7 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET',
5053
/**
5154
* Create requests with If-Modified-Since headers
5255
*
53-
* @param string $httpMethod
54-
* @param string $url
55-
*
56-
* @return Request
56+
* {@inheritdoc}
5757
*/
5858
protected function createRequest($httpMethod, $url)
5959
{

lib/Github/HttpClient/HttpClient.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class HttpClient implements HttpClientInterface
3232

3333
'api_limit' => 5000,
3434
'api_version' => 'beta',
35+
36+
'cache_dir' => null
3537
);
3638
/**
3739
* @var array

0 commit comments

Comments
 (0)