force bypassing cache (i.e. force getting from provider instead of getting from cache)?
wivaku opened this issue · 5 comments
General Information
GeocoderLaravel Version: 4.3.2
Laravel Version: 7.15.0
PHP Version: 7.4.7
Operating System and Version: macOS
Issue Description
How can I perform a request that bypasses the cache (i.e. force provider request)?
E.g. I have done a request using provider A and later want to perform the request using provider B.
The 2nd request returns the previous result from provider A.
Steps to Replicate
$result1 = app('geocoder')->using('google_maps')->reverse(40.7,-74)->get();
$result2 = app('geocoder')->using('locationiq')->reverse(40.7,-74)->get();
dd($result2->first()->getProvidedBy()); // google_maps
Thanks for submitting this. Will have to look into it, don't know off the top of my head.
Thanks Mike. Just in case: in the example I used two different providers, but the same question applies to requests using the same provider. E.g. the provider has updated the details of the Place and I want to force a new request.
Hi @wivaku, I added an option to disable caching as needed on a query-by-query bases. Please see the caching section in the README. Let me know how that works for you.
great, thanks! I read "You can disable caching on a query-by-query basis as needed" (doNotCache()
), as: "I make a request and the result is not cached".
A clearer description would perhaps be: ignore the existing cached result for that particular request, force the provider request, and cache the result from that request (and for me the method name forceRequest()
would be clearer).
I did a quick test and it appears it does that, so that's good.
However, it seems the setting is stored and not for a single request:
$result1 = app('geocoder')->using('google_maps')->reverse(40.7,-74)->get()->first()->getProvidedBy();
dump($result1); // google_maps
$result2 = app('geocoder')->using('locationiq')->doNotCache()->reverse(40.7,-74)->get()->first()->getProvidedBy();
dump($result2); // locationiq -> as expected
$result3 = app('geocoder')->using('opencage')->reverse(40.7,-74)->get()->first()->getProvidedBy();
dump($result3); // opencage -> expected: locationiq (cached)
Related, is there a way to determine if & when the result was cached? This so that I can decide if I want to make another request.
Hi @wivaku, thanks for the update. I went ahead and fixed the caching to only disable on the one request, and not keep the disabled state. I also updated caching to take the provider into account.
There is no way to determine if a query was cached or not, the result has no knowledge of how it was created.