I tried to pass a product bar code number that did not existed yet, then added it by contributing through the OpenFoodFact Android App, then called the API again and still no product found.
I flushed my cache, called the method again, and this time the correct response is returned.
Acceptance criteria
Only cache results for product found, do not cache product not found results (to allow subsequent retries to hopefully find the product if a contributor add it afterward).
What would a demo look like
Setup a Laravel cache driver (file, database, ...)
Call OpenFoodFacts::barcode($code);, where $code is a bar code of a product not in the database yet
Add the product (either through the mobile app or the website)
Call OpenFoodFacts::barcode($code);, where $code is a bar code of the product just added
No exception "Product not found", the result is the product JSON response
Notes
I noticed the cache is set after the JSON response it fetched. I did not dived into it in details, but if it is possible to figure out if the product is not found at this point, maybe we should prevent caching at this level?
Epic: #
Description
I tried to pass a product bar code number that did not existed yet, then added it by contributing through the OpenFoodFact Android App, then called the API again and still no product found.
I flushed my cache, called the method again, and this time the correct response is returned.
Acceptance criteria
Only cache results for product found, do not cache product not found results (to allow subsequent retries to hopefully find the product if a contributor add it afterward).
What would a demo look like
OpenFoodFacts::barcode($code);
, where$code
is a bar code of a product not in the database yetOpenFoodFacts::barcode($code);
, where$code
is a bar code of the product just addedNotes
I noticed the cache is set after the JSON response it fetched. I did not dived into it in details, but if it is possible to figure out if the product is not found at this point, maybe we should prevent caching at this level?
https://github.com/openfoodfacts/openfoodfacts-php/blob/develop/src/Api.php#L431-L435
Edit: In fact, I just tried to dd at this point, by testing with product number "3760314500074", and the response is the following:
So the fix for me (if you think it make sense), would be to update the code like this
Tasks