Ehcache Vs Static map cache implementation

随声附和 提交于 2019-12-09 12:41:32

问题


I have few tables with very few entries in them and they will never change dynamically . so i want to cache the whole table in memory to reduce load on DB. I can easily achieve that by a static Map and populating the map in a static block.

i was wondering whether the same is possible in a more effective way by Ehcache + hibernate?


回答1:


The advantage of a real second-level cache over a static map is that you get the advantage of in-memory access by still keeping the same way of defining, accessing and traversing your entities: by using the Hibernate session (or entity manager).

You may keep relationships with other entities (even not cached); you may use a query cache and still perform queries over these entities (and results of these queries will be cached as well).

In short, it's transparent, offers more options as Bozho said, and is much easier to use because cached entties are used the same way as other entities.




回答2:


Ehcache has a lot more features than a Map:

  • limit the maximum number of elements in memory
  • overflow to disk (if the above number is exceeded)
  • set a time-to-live and time-to-idle for elements
  • allows replication within a cluster

If you don't need any of those, you can safely use a Map - it will be easier to configure.



来源:https://stackoverflow.com/questions/6120870/ehcache-vs-static-map-cache-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!