Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## EHcache as standalone per JVM read only cache
- There are situations where you would want to cache read only values in the application server where the cache
- is local to the JVM. EHcache will provide feature like per-JVM cache, max number of entries, TTL enforcement
- and offload to disk.
- With legacy application there are lots of database hits for every page load. The problem that we are trying
- to solve here is where a read only value is fetched frequently in the application code causing a hit on the
- database. To solve this we are adding a per JVM, EHcache caching layer for this **read-only** only values.
- What you will need to consider is the heap size of your JVM as the cached values will be stored in the heap.
- ### Steps:
- 1. Add a dependency to ehcache, I'm using hibernate-ehcache.
- 2. Add a new cache in the ehcache.xml file.
- ```
- <cache name="com.nilath.localised.readonly.store"
- maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="0"
- timeToLiveSeconds="0" overflowToDisk="false" />
- ```
- 3. Create a Spring component LocalisedReadonlyEhCache that uses EHcache.
- 4. Use the LocalisedReadonlyEhCache in your services to write and read from the EHcache.
Add Comment
Please, Sign In to add comment