E
E
Eugene Burmakin2014-10-05 20:08:51
Ruby on Rails
Eugene Burmakin, 2014-10-05 20:08:51

How to cache received json in Rails?

Situation: I am processing a large json received from a remote server, the content of the json changes from time to time, so it needs to be updated.
Question: how can I cache the received data (about 15-30 megabytes, pull each time - it takes a noticeably long time) to work with them, and when will there be a signal that it's time to update the content, re-download json?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2014-10-05
@Freika

You do not know how to cache, or do not know where to get the signal that the data has been updated?
You can cache in Redis. To check the relevance of the data, you can do HEAD before the request itself, in theory it will return either the content modification date or the E-Tag.
The algorithm is something like this:
1. We pulled out the modification date or E-Tag from Redis.
2. Requested meta-information about JSON via HEAD.
3. Compared the meta information from HEAD with what was pulled from Redis
4. If they match, then you have the actual content
5. If they do not match, pull out JSON via GET, save the result and meta information in Redis.
6. Repeat with an interval of 5 minutes, for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question