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?
Ehcache has a lot more features than a Map:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With