-
Notifications
You must be signed in to change notification settings - Fork 76
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
Laravel Cache::store('file') #56
Comments
@M165437 Can you help us on this? |
@J-Yen Have a look at the file Route::get('/', function () {
Cache::store('file')->put('hello', 'world', 5);
$value = Cache::store('file')->get('hello');
return $value; // -> world
}); By the way, it's not one cache file but rather a folder structure. Correct, by default in |
Caching already works outside the Guzzle middleware and i already use it. Also your example works. |
Can you post more of your code? The part you posted above should work. |
|
Looks good. What about the response headers? Are you sure the response wants to be cached? You can check the headers with Laravel's dd() (dump and die) method, although you'd need to remove the public function post_request($postArgs)
{
$response = $this->client->request('POST', $this->connectionUrl, [
'form_params' => $postArgs,
]);
dd($response->getHeaders()); // temporarily
return json_decode($response->getBody());
} |
Ow yes that is the cause.
Thank you very much! |
You're welcome! :-) |
Now only figure out how to change it :-) |
@Kevinrob Honestly, I had the same struggle initially. :-) The |
You can use the |
So i have changed my code to:
But still no caching... |
Try this minimal example in use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Illuminate\Support\Facades\Cache;
use Kevinrob\GuzzleCache\CacheMiddleware;
use Kevinrob\GuzzleCache\Storage\LaravelCacheStorage;
use Kevinrob\GuzzleCache\Strategy\GreedyCacheStrategy;
Route::get('/guzzle-cache-test', function () {
$stack = HandlerStack::create();
$stack->push(new CacheMiddleware(
new GreedyCacheStrategy(
new LaravelCacheStorage(
Cache::store('file')
), 5000
)
), 'cache');
$client = new Client(['handler' => $stack]);
$responseBody = $client->get('http://github.com')->getBody();
return $responseBody->getContents();
}); |
What about File Permissions? Have you checked your error logs? Maybe Laravel isn't able to write the cache to the file system? |
No errors in the error logs. It should be able to write the cache to the file system because it's working with your example and in the rest of my code? |
It is a Lumen project, can this be a problem? |
That's quite a valuable info. Did you uncommented the |
Well, of course, otherwise the caching wouldn't work at all. |
So, if my example works, it's obviously not a problem with the middleware. |
yes i did uncommented the $app->withFacades() method. |
It works in Laravel. Lumen and Laravel are not the same thing. Something that works in Lumen will probably work in Laravel but not necessarily vice versa. Next time please specify your framework up front. The Laravel interface was created for and tested with Laravel. I don't know if it works with Lumen. |
Yes you're right I forgot an important detail. Nevertheless thank you very much for the quick help. |
Out of curiosity I set up a Lumen project. The route example above works fine. So the LaravelCacheStorage interface is Lumen compatible as well. :-) |
Can we close this issue? |
Yes, I think so. |
I use this to check if cache works. Hope it help someone :) use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Illuminate\Support\Facades\Cache;
use Kevinrob\GuzzleCache\CacheMiddleware;
use Kevinrob\GuzzleCache\Storage\LaravelCacheStorage;
use Kevinrob\GuzzleCache\Strategy\GreedyCacheStrategy;
Route::get('/guzzle-cache-test', function () {
$stack = HandlerStack::create();
$stack->push(new CacheMiddleware(
new GreedyCacheStrategy(
new LaravelCacheStorage(
Cache::store('file')
), 5
)
), 'cache');
$client = new Client(['handler' => $stack]);
$responseBody = $client->get('http://localhost:1234/time.php')->getBody();
return $responseBody->getContents();
}); // http://localhost:1234/time.php
echo 'SERVER TIME: ' . date('Y-m-d H:i:s') . PHP_EOL; If cache works, time will be increased by 5 seconds. |
This method working for me |
Does the following code work?
Where is the cache saved? Normally in storage/framework/cache but i don't find the cache file.
The text was updated successfully, but these errors were encountered: