S
S
semki0962018-03-14 10:34:11
caching
semki096, 2018-03-14 10:34:11

Where in my case is it better to save the data - to a file or to the mysql database?

There is data, they are read every 5 minutes from a third-party service, and I build a graph based on them. Initially, the data was stored in the database.
But there is a lot of data and I thought - maybe it's worth caching them on the server side? And then take data from the cache and draw a graph on the client side?
And suddenly I thought - why am I writing to the database at all, maybe it’s more correct to write to a file right away?
Discuss me, what's the best way to do it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander null, 2018-03-14
@semki096

The database already writes to a file)) But the database has tools for working with this data.
If you need to immediately contact several data sets (for example, for a period), then the database will be faster.
If all the data is available and stored in a single copy, then how the option to save them in .json and directly load them in the frontend
It all depends on how you plan to use them!

D
doublench21, 2018-03-14
@doublench21

Nothing is clear from your reasoning. Then you take data from a third-party service and write it to the database. Then you start talking about their caching. And then all of a sudden you start mentioning writing to a file.
If you write data to the database, then let it stay that way. Why, what's the point of the fact that you start writing data to a file ...
Of course, you need to cache, but what does it have to do with it? ( https://habrahabr.ru/company/zerotech/blog/316316/)

R
Roman Mirilaczvili, 2018-04-04
@2ord

But there is a lot of data and I thought - maybe it's worth caching them on the server side? And then take data from the cache and draw a graph on the client side?

The use of Key / Value storages like Memcached / TaranTool / Redis suggests itself.
When plotting a graph, the data for the graph is first searched for some key, say "reports/report1000". If there is no such key, then the data is requested from a third-party service and placed according to that key.
It is advisable to put the data in the cache with an expiration date, after which the k / v storage itself cleans up from irrelevant data.
You can store data from a third-party service in the cache as is (serialized into a string, of course), or you can preprocess it. You can simply store both unstructured data and in JSON, XML and other formats.
One caveat: the data must be small in size, otherwise the k / v storage will eat a lot of memory, since all the data is in RAM.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question