java java中动态缓存和静态缓存的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14168312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
difference between dynamic cache and static cache in java
提问by Reachgoals
We were looking to develop a cache mechanism and came across terms like dynamic cache and static cache. What is dynamic cache and static cache? Can any one help me to understand with example with respect to java?
我们正在寻求开发一种缓存机制,并遇到了诸如动态缓存和静态缓存之类的术语。什么是动态缓存和静态缓存?任何人都可以帮助我以有关 Java 的示例来理解吗?
回答by Evgeniy Dorofeev
To put it short, static cache is readonly cache and dynamic cache is read and write. Usage examples
简而言之,静态缓存是只读缓存,动态缓存是读写。使用示例
Static: on program startup we load some reference data from DB table into a cache once. Now our cache returns data by key instead of making requests to DB.
静态:在程序启动时,我们将一些参考数据从 DB 表加载到缓存中。现在我们的缓存通过键返回数据而不是向数据库发出请求。
Dynamic: we have Staff DAO with a cache. On getStaffById we first look in the cache and if it's there return; otherwise read it from DB put it in cache and return. On remove/update we remove/update both in cache and DB.
动态:我们有带缓存的 Staff DAO。在 getStaffById 上,我们首先查看缓存,如果有则返回;否则从数据库读取它把它放在缓存中并返回。在删除/更新时,我们在缓存和数据库中删除/更新。