How to Flush the Cache in Ehcache
Ehcache is designed to assist your computer in storing and interpreting web-related information so that it can access information more quickly with less strain on both your computer and the server it is connecting to. Despite several optimizations techniques, the stored cache from Ehcache can take up a considerable amount of your system's memory, but you can easily solve this problem by flushing, also known as deleting, the memory from your computer.
Instructions
-
-
1
Open Ehcache. By default, the program has an interface that can only be communicated with through strings of code, similar to Window's Command Prompt window.
-
2
Type the following command to flush cache from the program:
import net.sf.ehcache.Element
import net.sf.ehcache.CacheManager
import net.sf.ehcache.Cachedef cachemgr = new CacheManager("D:/mPortal/workspace_new_cvs_structure/EhCacheDemo/config/change_listener_cache.xml")
def deltacache = cachemgr.getCache("deltaCache")def deltaclone = new Cache("deltaCacheClone", 10000,null, true,cachemgr.getDiskStorePath(), true, 120,120,true, 120,null)
cachemgr.addCache(deltaclone)println "Migration about to begin"
println "Size of the original cache : ${deltacache.getSize()}"
println "Size of the clone : ${deltaclone.getSize()}"deltacache.getKeys().each{
ele = deltacache.get(it)
deltaclone.put(new Element (ele.getKey(),ele.getValue()))
}println "Size of the original cache after migration : ${deltacache.getSize()}"
println "Size of the clone after migration : ${deltaclone.getSize()}"println "Migration successfully finished.."
deltacache.flush()
deltaclone.flush()This will flush the cache and display relevant data, such as the amount of memory your computer saved by completing the process.
-
-
3
Press the "Enter" key to execute the command. This may take several minutes or just a few seconds, largely depending on the amount of cache currently stored on your computer. Once finished, you are free to exit the program.
-
1