Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about a problem with v. 2 cache - missing cache files #502

Closed
ksdev-pl opened this issue Jan 11, 2017 · 5 comments
Closed

Question about a problem with v. 2 cache - missing cache files #502

ksdev-pl opened this issue Jan 11, 2017 · 5 comments
Milestone

Comments

@ksdev-pl
Copy link

Hi

A v. 2.0.1 noob question:

In the v. 1.* to use the cache I've used:

$githubClient = new \Github\Client(
    new \Github\HttpClient\CachedHttpClient(['cache_dir' => storage_path('app/cache')])
);

$paginator = new \Github\ResultPager($githubClient);

// The rest of the code with requests

I see the cache files using this code, so I know they are created.

In the v. 2 I've tried the php-cache/filesystem-adapter:

use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Cache\Adapter\Filesystem\FilesystemCachePool;

// ...

$filesystemAdapter = new Local(storage_path('app')); // storage_path: laravel method pointing to "app" storage folder
$filesystem        = new Filesystem($filesystemAdapter);

$pool = new FilesystemCachePool($filesystem);

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

$paginator = new \Github\ResultPager($client);

// The rest of the code with requests - exactly the same as for the 1.*

The end result is the same as in the v 1.* - that is, I'm successfully downloading a list of gists from github. During debugging I've checked that the cache plugin is added correctly.

The difference is - in the v. 2, with the code as seen above, no cache files are created.

The path is correct, because a "cache" folder is created in laravel storage app folder - but it's empty.

I've tried also with madewithlove/illuminate-psr-cache-bridge. The code with it is somewhat different (the folder path is configured in laravel config), the end result is correct and without errors (I'm downloading a list of gists), but I don't see the cache files, they are not created.

What am I missing? Or how to debug it, any help with where to check what the problem is?

@Nyholm
Copy link
Collaborator

Nyholm commented Jan 12, 2017

Thank you for a detailed issue. I've copied your code and tested it myself. It all seams to work properly.

The only thing I'm not familiar with is storage_path. I replaced it with

$filesystemAdapter = new Local(__DIR__);

This will create a cache folder next to the current file. In that cache folder there your cache files will appear. (Be aware that IDEs could be quite slow in showing new files.)

@ksdev-pl
Copy link
Author

Thank you for the answer. I will test it later again and I'll let you know.

@ksdev-pl
Copy link
Author

I've made more tests:

When I'm not authenticating, this code produces a cache file:

$filesystemAdapter = new Local(storage_path('app'));
$filesystem        = new Filesystem($filesystemAdapter);

$pool = new FilesystemCachePool($filesystem);

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

$paginator = new \Github\ResultPager($client);

// $client->authenticate($token, null, \Github\Client::AUTH_HTTP_TOKEN);

$gistsApi = $client->api('gists');

$rawUserGists = $paginator->fetch($gistsApi, 'all');

But when I add authentication, no cache file is created:

$filesystemAdapter = new Local(storage_path('app'));
$filesystem        = new Filesystem($filesystemAdapter);

$pool = new FilesystemCachePool($filesystem);

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

$paginator = new \Github\ResultPager($client);

$client->authenticate($token, null, \Github\Client::AUTH_HTTP_TOKEN);

$gistsApi = $client->api('gists');

$rawUserGists = $paginator->fetch($gistsApi, 'all');

In both cases the end result is correct and without errors, the gists are downloaded.

Am I doing something wrong? What can be the reason of missing cache files with authentication? Or how can I debug it to narrow down the problem?

@Anahkiasen
Copy link

Anahkiasen commented Jan 28, 2017

It seems the issue is this line in the HTTP CachePlugin, since all Github responses return the private Cache-Control directive, nothing is ever cached.

But that directive is only for shared caches, you are allowed to cache the response into a private cache, which is my usecase.

Related issue on php-http's end php-http/cache-plugin#3

@acrobat
Copy link
Collaborator

acrobat commented Feb 14, 2017

Hmm this indeed explains the problem I have that nothing is cached, hopefully we have some kind of solution soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants