Attributes of Spring Cache
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 :-
- maxElementsInMemory- How many elements you can store in cache
- overflowToDisk-The attribute overflowToDisk is true, meaning that whenever the maximum number of in-memory objects is reached, objects are swapped to disk
- diskPersistent – if diskPersistent is false, it means when application server is restarted, in-memory cache is lost.
- ttl(time to live seconds)- It denotes for how many seconds element will remain in cache?
- 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:
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.
[groovy]
studentCache(EhCacheFactoryBean) { bean ->
cacheManager = ref("springcacheCacheManager")
cacheName = "studentCache"
eternal = false
diskPersistent = false
memoryStoreEvictionPolicy = "LRU"
ttl = 3000
}
[/groovy]
Hope this code will help you 🙂
To know more about Cache, you can take the reference by using below link.
http://grails.org/plugin/springcache
http://www.tothenew.com/blog/how-to-integrate-spring-cache-plugin-with-grails/