是的,cache-ehcache
插件絕對支持TTL和EhCache原生支持的所有緩存配置屬性。如文檔中所述,基本緩存插件實現了一個不支持TTL的簡單內存緩存,但緩存DSL將通過任何未知配置設置傳遞給基礎緩存提供程序。
您可以通過添加以下內容Config.groovy
或CacheConfig.groovy
配置了Ehcache設置:
grails.cache.config = {
cache {
name 'mycache'
}
//this is not a cache, it's 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 for CacheConfiguration緩存屬性。您還可以通過登錄grails.plugin.cache
和net.sf.ehcache
來啓用緩存的詳細調試日誌記錄。
請注意,Grails緩存插件實現了與本機EhCache緩存管理器不同且獨立的緩存管理器。如果您已經直接配置EhCache(使用ehcache.xml或其他方式),那麼這些緩存將與Grails插件管理的緩存分開運行。
注意:Cache-EhCache插件的舊版本確實存在一個錯誤,其中TTL設置未正確設置且對象在一年內過期;這是固定在Grails-Cache-Ehcache 1.1。
這個問題被問了很久以前,但看到的是https:/ /jira.grails.org/browse/GPCACHEEHCACHE-6 –
@Ken現在鏈接已損壞 – GreenGiant