开发者

Ehcache Vs Static map cache implementation

I have few tables with very few entries in them and they w开发者_Go百科ill 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜