You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used your implementation of the filesystem cache.
- Delete all files under the cache directory `github-api-cache`.
- Set properly your authentication method (I used token).
- Run the following code once after a proper Client instantiation with cache:
```
$commits_article_1 = ResponseMediator::getContent($client->getHttpClient()->get("repos/jrean/askjong.com/commits?sha=master&path=articles/hello-world.md"));
$rateLimit = ResponseMediator::getContent($client->getHttpClient()->get("rate_limit"));
var_dump($rateLimit);
$commits_article_2 = ResponseMediator::getContent($client->getHttpClient()->get("repos/jrean/askjong.com/commits?sha=master&path=articles/this-is-a-first-article.md"));
$rateLimit = ResponseMediator::getContent($client->getHttpClient()->get("rate_limit"));
var_dump($rateLimit);
```
4 requests against Github Api:
- 1 query to fetch the commits for the `articles/hello-world.md` file. (`Guzzle\Http\Message\Response` status code is 200)
- 1 query to fetch the commits for the `articles/this-is-a-first-article.md` file. (`Guzzle\Http\Message\Response` status code is 200)
- 2 queries to fetch the rate_limit (doesn't count again the rate limit). (`Guzzle\Http\Message\Response` status code is 200)
Once this code has run the cache directory `github-api-cache` will have 6 files (3 for each queries including the `rate_limit` query + 3 `.etag` files)
**The `rate_limit` should / must decrease by 2** (a call to `rate_limit` doesn't count against Github).
--
- Run the same code again.
4 requests against Github Api:
- 1 query to fetch the commits for the `articles/hello-world.md` file. (`Guzzle\Http\Message\Response` status code is 304, cache is used)
- 1 query to fetch the commits for the `articles/this-is-a-first-article.md` file. (`Guzzle\Http\Message\Response` status code is 304, cache is user)
- 2 queries to fetch the rate_limit (doesn't count again the rate limit). (`Guzzle\Http\Message\Response` status code is 200)
**The `rate_limit` don't move** (a call to `rate_limit` doesn't count against Github).
--
- Run the following code which use your wrapping methods against Github Api (Notice we are requesting the same informations):
**It should use the cache but it will not.** (I explain why just after).
```
$commits_article_1 = $client->api('repo')->commits()->all('jrean', 'askjong.com', array('sha' => 'master', 'path' => 'articles/hello-world.md'));
$rateLimit = ResponseMediator::getContent($client->getHttpClient()->get("rate_limit"));
var_dump($rateLimit);
$commits_article_2 = $client->api('repo')->commits()->all('jrean', 'askjong.com', array('sha' => 'master', 'path' => 'articles/this-is-a-first-article.md'));
$rateLimit = ResponseMediator::getContent($client->getHttpClient()->get("rate_limit"));
var_dump($rateLimit);
```
4 requests against Github Api:
- 1 query to fetch the commits for the `articles/hello-world.md` file. (`Guzzle\Http\Message\Response` status code is 200)
- 1 query to fetch the commits for the `articles/this-is-a-first-article.md` file. (`Guzzle\Http\Message\Response` status code is 200)
- 2 queries to fetch the rate_limit (doesn't count again the rate limit). (`Guzzle\Http\Message\Response` status code is 200)
Once this code has run the cache directory `github-api-cache` will have new files...
**The `rate_limit` decreases by 2** (a call to `rate_limit` doesn't count against Github). It should not decrease because we should use the cache!
--
- Run the same code again.
4 requests against Github Api:
- 1 query to fetch the commits for the `articles/hello-world.md` file. (`Guzzle\Http\Message\Response` status code is 200)
- 1 query to fetch the commits for the `articles/this-is-a-first-article.md` file. (`Guzzle\Http\Message\Response` status code is 200)
- 2 queries to fetch the rate_limit (doesn't count again the rate limit). (`Guzzle\Http\Message\Response` status code is 200)
**The `rate_limit` decreases by 2 again** (a call to `rate_limit` doesn't count against Github). It should not decrease because we should use the cache!
- Run the same code again and it will still decrease your `rate_limit`...
--
# Solution
This issue comes from the use of `$path`:
`protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array())`
Then here:
`if ($modifiedAt = $this->getCache()->getModifiedSince($path)) {`
And:
`if ($etag = $this->getCache()->getETag($path)) {`
`$path` doesn't take care of the `$options` array which contains the sub array for the `query` parameters!
So each time `getModifiedSince($path)` and `getETag($path)` will work with an incomplete path because it doesn't know query parameters (if they exists). In that exemple `$path` value will always be `repos/jrean/askjong.com/commits` and it should be `repos/jrean/askjong.com/commits?sha=master&path=articles/hello-world.md`.
See my code modifications to fix the problem.
(I didn't use `$request->getQuery()` because it returns query parameters but encoded and it is not acceptable because when we want to construct our own queries like `repos/jrean/askjong.com/commits?sha=master&path=articles/hello-world.md` we won't encode parameters)
By applying this patch we can now use the cache as it should be :)
I started this issue a few days ago.
KnpLabs#262
0 commit comments