Guest User

Untitled

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