4
4
4upik2021-03-18 11:50:34
linux
4upik, 2021-03-18 11:50:34

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

4 answer(s)
E
Eugene, 2021-03-18
@Nc_Soft

You can cache the entire page in nginx , but then you will have to take the price with a script through Ajax.

R
Romses Panagiotis, 2021-03-18
@romesses

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.

S
Sergey, 2021-03-18
@begemot_sun

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.

V
Valentine, 2021-03-18
@ProFfeSsoRr

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 question

Ask a Question

731 491 924 answers to any question