Attributes of Spring Cache

25 / Sep / 2012 by Mohit Garg 0 comments

In my previous blog, i have mentioned how to integrate spring cache plugin in grails. In this blog we will see how we can use different attributes of cache.

Different attributes of cache :-

  1. maxElementsInMemory- How many elements you can store in cache
  2. overflowToDisk-The attribute overflowToDisk is true, meaning that whenever the maximum number of in-memory objects is reached, objects are swapped to disk
  3. diskPersistent – if diskPersistent is false, it means when application server is restarted, in-memory cache is lost.
  4. ttl(time to live seconds)- It denotes for how many seconds element will remain in cache?
  5. memoryStoreEvictionPolicy – It is used to evict element from in-memory when the maximum number of in-memory objects is reached . Different type of eviction policy:
  6. a) LRU (Least Recently Used): Oldest element will be evicted.
    b) LFU (Least Frequently Used): Element with least hits will be evicted.

In grails, you can implement different cache attributes like this way.

studentCache(EhCacheFactoryBean) { bean ->
cacheManager = ref("springcacheCacheManager")
cacheName = "studentCache"
eternal = false
diskPersistent = false
memoryStoreEvictionPolicy = "LRU"
ttl = 3000

Hope this code will help you 🙂

To know more about Cache, you can take the reference by using below link.


Leave a Reply

Your email address will not be published. Required fields are marked *