S
S
Semyon Semyonov2015-02-21 21:19:33
Ruby on Rails
Semyon Semyonov, 2015-02-21 21:19:33

How to properly cache rarely changed data?

When a user enters the profile, they have transaction and event panels on the right. They are not formed in a simple way, i.e. some data is parsed, then it is formed and all that. And so this panel on all project is always visible to the user. Wherever you go, it will be everywhere. But it turns out that each page transition takes 1.5 seconds to load because of this block. Transactions, like events, can change with an indefinite frequency. Those. for example, transactions may be added today, but not tomorrow, and after tomorrow they may appear every half hour.
I'm not very familiar with caching (apart from the fact that some data is put into memory or somewhere else and then just twitched from there, and a new lot of requests are not made), but if I understand correctly, caching will not work in this case. Those. it will not work because the data can change and it may turn out that a new transaction or event has appeared, but the user will not see it.
Or I'm wrong? Please explain how to be in a similar situation. Considering that it takes 1.5 seconds to load some block there, this is a direct waste of the "budget". :)
PS Oh yes, I forgot to add. Transactions and events depend on the user ID. Perhaps this is important.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey Krasnodemsky, 2015-02-22
@Prognosticator

You have the answer in the question
Check it out.
Store panel data in Memcached. Show "outdated" data if it is not critical for the application.
Or upload data via ajax.

T
thepry, 2015-02-22
@thepry

In my noob opinion, here you need to understand what data can be used in order to understand whether new transactions have appeared or not. And then use them - either get each time data sufficient for this output, or somewhere (eg in a table) store information about the date of the last transaction and, if it differs from that recorded in the cache, then update it.

V
vsuhachev, 2015-02-22
@vsuhachev

You are wrong, caching will work. But the cache needs to be updated and it greatly depends on where and how your transaction data is stored. In general, there are the following options:
1) Reset the cache after a certain period of time. Like every hour.
2) Reset the cache on an event. For example, the function to create transactions resets the cache
3) Reset the cache by the update date of the cached object. This is when the creation time of the cached data is stored and when accessing the cache it is compared with the modification time of the object, if it is later, the cache is updated.
As you have already been advised - familiarize yourself with the caching system. In 4 rails, it is out of the box and quite advanced.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question