1

I am using the Magento2 REST APIs that don't have any built-in cache, so I have introduced one based on a public module. Basically what it does is to cache the result of a GET request on products (GET requests for paths that match ^\/V1\/products).

Obviously, details like the stock quantity are not valid anymore if the cache is not invalidated every time someone places an order, but it seems a terrible option.

The only thing I can think of is, based on the website needs, to calculate a good cache TTL (probably X minutes), and accept that the information about stock quantities can be wrong for a short period (X - Y minutes).

Of course a POST request to add a product in the cart will always give the correct output (error if out of stock), but there can be some inconsistency with what is shown.

So, my question is: is this a valid approach? If the answer is no, can you point me in the right direction?

1 Answer 1

2

Stumbled across this today. It may work for you or give you some inspiration (Disclaimer: I've not tried it)

https://github.com/magespecialist/m2-MSP_APIEnhancer

If you write your own I wouldn't use a ttl. Better would be to use the cache invalidation system and just invalidate the now stale sections. Much more tricky than invalidating the whole cache.

Sign up to request clarification or add additional context in comments.

1 Comment

It's buggy. it causes Magento to instantiate Magento\Framework\Locale\Resolver instead of Magento\Backend\Model\Locale\Resolver in admin area

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.