Closed khalyomede closed 1 year ago
SonarCloud Quality Gate failed.
0 Bugs
0 Vulnerabilities
4 Security Hotspots
3 Code Smells
No Coverage information
0.0% Duplication
I'd think it would be best to let the user of this library decide, if the cache should be used - and not hard-code it like we both did in the past :sweat_smile:
I get situations when I scan a product, the product does not exist yet, then I add it using the OpenFoodFact Android app, and re-run the API call but the "product not found" result is still in cache despite the product exist in the O.F.Fact database.
@Dwarfex Can you give me examples when you see caching the result of the API if the product is not found is legit?
If the reason is legit, then I propose to offer the possibility to flush the cache of the specific product (to do on another PR) if you do not agree to merge this PR.
Currently I have to fix this using an hard coded base URL in my code base (Laravel):
$code = $request->code;
$product = OpenFoodFacts::barcode($code);
if (empty($product)) {
Cache::forget(md5("https://world.openfoodfacts.org/api/v0/product/$code.json"));
throw new NoProductFoundException();
}
SonarCloud Quality Gate failed.
0 Bugs
0 Vulnerabilities
4 Security Hotspots
3 Code Smells
No Coverage information
0.0% Duplication
This PR prevents "product not found" responses to be cached. It will help in case the product is not found at a given moment, then a contributor adds this product.
With this PR, next time the API is called, the product will be found, and will be cached (instead of caching the "product not found" response, and never being able to get the product found response until the cache is flushed).