0

ehache.xml for cache configuration has been created. But setting in this file works only for hibernate 2L cache For custom caches (for example caching service methods invocation: @Cacheable('someCache') ) cache plugin settings don't work

<cache name="someCache" maxElementsInMemory="100" timeToLiveSeconds="86400" timeToIdleSeconds="86400"/>

But if setting in Config.groovy -- it works

grails.cache.config = {
  cache {
    name 'someCache'
    timeToIdleSeconds 86400
    timeToLiveSeconds 86400
    maxElementsInMemory 100
  }
}

Like for springcache plugin I tried to share cacheManager

cacheManager(EhCacheManagerFactoryBean) {
    shared = true
}

Where is no result

Now I have to write configuration in two places and for cache managing use grailsCacheManager.cacheManager & CacheManager.instance

Any ideas?

Upd: Configuration in Config.groovy has been created

import  grails.test.Test
grails.cache.config = {
  domain {
    name Test
    timeToIdleSeconds 3600
    timeToLiveSeconds 3600
    maxElementsInMemory 50000
  }
  cache {
    name 'myCache'
    timeToIdleSeconds 86400
    timeToLiveSeconds 86400
    maxElementsInMemory 1000
  }
  defaults {
    eternal false
    overflowToDisk false
    diskPersistent false
    timeToIdleSeconds 600
    timeToLiveSeconds 3600
    memoryStoreEvictionPolicy 'LRU'
  }
}

Domain:

package grails.test
class Test {
  static mapping = {
    cache 'nonstrict-read-write'
    version false
  }
}

and in controller I call:

Test.get(params.id)

But cache is empty: grails.test.Test cur size:0

Custom cache "myCache" -- work

4

1 回答 1

1

查看 Grails ehcache 插件文档。它包含解释如何使用 Grails 缓存插件 DSL 配置 Hibernate 二级缓存的部分。查找“Hibernate 二级缓存”和“Hibernate 域类二级缓存”

于 2013-04-09T10:42:02.453 回答