如何将数据临时存储,并在每隔10分钟将其存储到数据库中?

huangapple go评论119阅读模式
英文:

How to keep data temporary somewhere and using the same to store it in database every 10 minutes?

问题

我想要解决一个设计问题,在这个问题中,我收到了多个事件数据,但是对于一种数据,我不想在事件发生后立即存储该事件,而是想要等待 10 分钟,让这些事件发生,但同时要保留事件发生次数,以便一旦达到 10 分钟间隔,我可以将计数与事件累积存储起来,这将减少涉及数据库的操作次数。

例如,假设我有三种事件,分别是 EV1、EV2 和 EV3。事件 EV3 在我的应用程序中以非常大的数量发生,其他两种事件不太频繁。但我不关心捕获事件的每次触发,我只关心知道事件 EV3 发生了多少次。因此,考虑在 10 分钟的间隔内捕获 EV3 的次数,通过在某个地方实时存储计数,并在每 10 分钟进行一次存储。

请为此提供一个好的、简单的设计,可以在 Java 中使用。提前感谢您的建议。

英文:

I want to solve one of my design problem where I am getting several events data but for one kind of data I do not want to store the event as soon as it happens instead I want to wait for 10 minutes to let them happen those event but want to keep the number of event counts happening so that once the interval of 10 minutes reaches I can store the count with the event cumulatively which will reduce the number of operation being involve with database.

For example
Let's say I have three events namely EV1, EV2 and EV3. Event EV3 happens in my application in very large volume other two events are less frequent. But I am not concerns to capture every trigger of the event but I am interested to know how many times that event (EV3) happened. So thinking to capture the EV3 count in 10 minute of interval by storing the counts somewhere on the fly and dump the same in every 10 minutes.

Please suggest a good and simple design for it which can be used in Java, Thanks in advance.

答案1

得分: 0

你可以使用缓存来临时存储你的数据(例如 Redis),然后将数据保存到你的数据库。不确定你的事件是什么,但这是一般的设计方法,用于临时存储数据并减少数据库写入。

英文:

You can use caching to store your data temporarily(like Redis) and then save the data to your db. Not sure what your event is but this is general design followed to store data temporarily and reduce db writes.

huangapple
  • 本文由 发表于 2020年8月16日 16:19:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/63434681.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定