F
F
Fdrsmrdv2020-05-28 17:38:38
caching
Fdrsmrdv, 2020-05-28 17:38:38

What is the best way to cache received data from the server?

Hello!

Introductory:

We have a web admin panel for the *XX* service. It has settings for:

- users
- products
- store addresses
- customer tags
- product types

- etc.

For example , tags and product types are edited extremely rarely, but are requested frequently. We want to cache them somewhere in the localstore and check every time the page is updated to see if updatetAt has changed. If they have not changed, then we get it from the localstory

Question:

How to properly perform caching of this kind?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dima Pautov, 2020-05-28
@bootd

The server should cache, and the front should request, albeit the same thing.
Either request 1, and then simply check if there is no data in the variable, request.
localstorage is not a 1TB hard drive for you. There can be a meager amount of data and it’s stupid to keep a certain database there, besides, it’s more cumbersome to make changes there if you need to change 1 element.
In addition, if the data on the server has changed, how should the front understand this? In my opinion, a stupid decision that will not lead to anything good.

A
Andrew, 2020-05-28
@AndrewRusinas

localStorage is limited to five megabytes, so it can break all of a sudden. For your situation, I advise you to consider IndexedDB .

S
szanislo, 2020-05-28
@szanislo

Look towards Hazelcast or redis

R
Robur, 2020-05-29
@Robur

If there is little data, then it can be stored in localstorage, if there is a lot, cache at the HTTP level, let the browser sort it out.
The server knows when the data has changed and can signal the browser via etag for example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question