🎉 New Super Feature! Elementor Integration Added to our eCommerce Mobile App.

PrestaShop Webservice API Caching Trick to Save Network

Prevent sending duplicate content

Based on this Pull Request, it's possible to do some sort of caching when data has not changed. But how?

When we send a request to one of the PrestaShop webservices API, there is a header within the response:

Content-Sha1

This header contains the calculated hash value of the requested content (that CRUD resource). For example, when we request for product with ID=2, PrestaShop fetches the data and calculates its hash, then puts the result in Content-Sha1 header and returns back to the client.

In the subsequent requests, when we request the same resource (product with ID=2), we also set this header Content-Sha1. The back-end API fetches the data and calculates the hash again. This time it compares the hash result with the header value sent from client. If the hashes are same, PrestaShop returns 304 Not Modified, but if they are not equal, PrestaShop returns the data.

How to do caching?

Take attention that this practice is useful for large data which saves network traffic, and the client-side should take care of the caching mechanism. It's good to mention that the fetching and processing data still will be done by PrestaShop.


Posted 1 year ago by Sam Berry