Grails graphics module for ehcache cache and TTL values

Can anyone confirm TTL settings, for example. can timeToLiveSeconds be set using the Grails pins plugin with the ehcache extension?

The documentation for the base plugin explicitly indicates that TTL is not supported, but the ehcache extension mentions these values. So far, I have not been able to set TTL values ​​for my cache:

grails.cache.config = {
    cache {
        name 'messages'
        maxElementsInMemory 1000
        eternal false
        timeToLiveSeconds 120
        overflowToDisk false
        memoryStoreEvictionPolicy 'LRU'
    }
}

@Cacheable('messages')
def getMessages()

However, messages remain cached indefinitely. I can manually clear the cache using the @CacheEvict annotation, but I was hoping that TTL would be supported when using the ehcache extension.

thank

+5
source share
3 answers

, cache-ehcache TTL , EhCache. , , TTL, Cache DSL .

EhCache, Config.groovy CacheConfig.groovy:

grails.cache.config = {
    cache {
        name 'mycache'
    }

    //this is not a cache, it a set of default configs to apply to other caches
    defaults {
        eternal false
        overflowToDisk true
        maxElementsInMemory 10000
        maxElementsOnDisk 10000000
        timeToLiveSeconds 300
        timeToIdleSeconds 0
    }
}

:

grailsCacheManager.cacheNames.each { 
   def config = grailsCacheManager.getCache(it).nativeCache.cacheConfiguration
   println "timeToLiveSeconds: ${config.timeToLiveSeconds}"
   println "timeToIdleSeconds: ${config.timeToIdleSeconds}"
}

EhCache javadoc CacheConfiguration . grails.plugin.cache net.sf.ehcache.

, Grails , EhCache. EhCache ( ehcache.xml ), , Grails.

. Cache-EhCache , TTL , ; Grails-Cache-Ehcache 1.1.

+6

TTL ehcache. ? :

compile ":cache-ehcache:1.0.0"

BuildConfig.groovy . Grails, .

0

I can solve this problem by overriding the configuration at startup with a grails-app/conf/BootStrap.groovyscript.

For example, this is a script to override the default lifetime for up to 60 seconds of a cache named "mycache":

class BootStrap {

    def grailsCacheManager

    def init = { servletContext ->
        grailsCacheManager.getCache("mycache").nativeCache
                        .cacheConfiguration.timeToLiveSeconds = 60
    }
    def destroy = {
    }
}
0
source

All Articles