Persistent cache not reloading on restart

Anonymous
2012-02-14
2013-05-14

  • Anonymous
    2012-02-14

    I am currently working on a Grails plugin to create a disk persistent cache using EhCache.  I have everything working except reloading the cache on restart.  I can see that as I use my app, values are being cached correctly.  I can see the cache's .data and .index files are created.  However, when the app is restarted, both files are cleared out and the cache is not reloaded.  I do have the ShutdownListener configured in my web.xml.  Any help anyone can provide is appreciated!

    ehcache.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <ehcache>
        <!-- I am using this directory only for development -->
        <diskStore path="/tmp"/>
        <defaultCache maxElementsInMemory="1000" 
                      eternal="false" 
                      timeToIdleSeconds="120" 
                      timeToLiveSeconds="120" 
                      overflowToDisk="false"/>
        <cache name="grails.plugin.persistent_cache.default"
            maxElementsInMemory="500" 
                    eternal="true"
                    overflowToDisk="true" 
                    timeToIdleSeconds="300" 
                    timeToLiveSeconds="600"
                    diskPersistent="true" 
                    diskExpiryThreadIntervalSeconds="1"
                    memoryStoreEvictionPolicy="LFU" />
    </ehcache>
    
     
  • Andrew Liles
    Andrew Liles
    2012-02-15

    (By the way, this forums is essentially closed.  You should re-post your question on the terracotta ehcache forum).

    The re-build from disk does work in my experience; my guess then is that your application lifecycle is not allowing the cache to be persisted.

    It is normal for the .data/.index files to be created on disc persistent caches, but these will be size 0.  The size only grows during cache shutdown, assuming there has be no overflow to disc.  Upon safe shutdown are those files non-zero?

    If they remain zero, try manually shutting down the cache using
    CacheManager.shutdown();
    just as an experiment.  If this works then perhaps the shutdown work is not working as you expect or shutting down too quickly.