简体   繁体   English

如何在我的Java应用程序中启用数据库缓存

[英]How to enable database cache in my java application

I have a scenario where i have a database which will be updated at any time by end user... my java application need to cache the data once any change in the database is done? 我有一种情况,我有这将在任何时间通过最终用户更新的数据库......我的Java应用程序需要一次数据库中的所有变化做缓存的数据? How is it possible? 这怎么可能? Some one help me in clearing this issue? 有人帮我清理这个问题?

I would like to know how to cache the database data once any updates is made in the database? 我想知道如何缓存数据库的数据,一旦任何更新是在数据库中进行?

You can register a stored procedure as trigger that notifies your Java application about the update. 您可以将存储过程注册为触发器,以将更新通知给Java应用程序。 Read about triggers here: https://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html 阅读关于触发器在这里: https://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html

Your question can be interpreted in different ways: 您的问题可以用不同的方式解释:

  • You want to minimize the latency between update in the database and the cache update. 您希望最小化数据库中更新和缓存更新之间的等待时间。 Eventual consistency is okay. 最终的一致性还可以。
  • The cache is kept consistent with the database content 缓存与数据库内容保持一致

The latter is much more difficult to achieve. 后者很难实现。 If consistency is required, then, at some point, the database transaction must wait until the application is notified and has acknowledged. 如果需要的一致性,然后,在某些时候,数据库事务必须等到申请通知的承认。 You will run into lots of interesting questions in the area of distributed computing. 你会遇到很多的分布式计算领域的有趣问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM