Answer the question
In order to leave comments, you need to log in
How to cache dynamic data in NGINX received via API?
There is an online store, the goods on the site are displayed directly from the supplier's API, including photos of the goods.
Problem: the speed of providing data to the end user, because the request passes from the user to our server - from our server - to the supplier's server and back to the end user.
There is also a problem with images, the supplier's server is in another country.
1. How can I cache (in files) product description and product photos, but not cache the price and display it without the cache?
2. Is it possible to cache at the nginx level in the database (mariadb)? or better files?
(Transfer all data from api to database - not yet possible)
Answer the question
In order to leave comments, you need to log in
You can cache the entire page in nginx , but then you will have to take the price with a script through Ajax.
As far as I understand, you can't cache without including the price of the provider as it's a content modification. And caching is a primitive mechanism.
Images are the easiest: you can just cache them, nginx can act as a cache proxy.
Those. refer to nginx, it already goes to its disk - if there is no picture (or it is expired), then it goes to the supplier.
In fact, the same thing can be done with the price only on files.
To get the price, you access a text file, if it is not expired - nginx gives it back, if it is expired - then nginx accesses your script, which pulls out the price from where it is needed and returns it in plain text.
There is SSI (you can cache everything except the page block with the price): https://habr.com/ru/post/428127/ Either display the price through JS, or do something else. On the second question - nginx caches to files and this is better, it does not know how to use it in the database and it is not necessary. Caching images is not a problem at all, this is a typical case for nginx ("static caching" it's called, there are many different options).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question