Caching springcache插件在grails中的使用
我一直在尝试将SpringCache添加到我的一个Spring托管服务中。我使用STS作为我的开发IDE 以下是我所做的:Caching springcache插件在grails中的使用,caching,grails,service,aspectj,ehcache,Caching,Grails,Service,Aspectj,Ehcache,我一直在尝试将SpringCache添加到我的一个Spring托管服务中。我使用STS作为我的开发IDE 以下是我所做的: 已安装springcache 1.3.1插件 在Config.groovy中添加了缓存配置: grails.spring.disable.aspectj.autoweaving = true springcache { enabled = true defaults { eternal = false diskPersistent = fa
grails.spring.disable.aspectj.autoweaving = true
springcache {
enabled = true
defaults {
eternal = false
diskPersistent = false
}
caches {
tripCache {
memoryStoreEvictionPolicy = "LRU"
}
}
}
@Cacheable
注释,如下所示:
int counter = 0
@Cacheable("testCache")
String testInc(String x) {
return (++counter).toString()
}
def testDashboard() {
[data:testService.testInc("1")]
}
int counter = 0
@Cacheable("testCache")
String testInc(String x) {
return (++counter).toString()
}
def testDashboard() {
[data:testService.testInc("1")]
}
testInc()
总是返回一个新值,即连续调用返回1、2、3等,这使我认为缓存不起作用。我是否错过了什么,并且没有正确打开缓存
我试着看看缓存是否工作正常,我钩住了ehcache-2.4.6的源代码,并在CachingAspect的invokeCachedMethod中设置了断点,但是当我运行我的应用程序时,上面的方法似乎没有被执行
我还尝试在缓存中查看“1”的值,看起来它是空的,即键“1”没有存储在缓存中。我在控制器测试方法中添加了以下两行:
Ehcache c = springcacheService.getOrCreateCache("testCache")
String x = c.get("1")
求求你,救命 基本上,我被这里的springcache文档误导了:
Config.groovy
应该具有grails.spring.disable.aspectj.autowiven=false
isntead的true
希望这对那些在同一问题上陷入困境的人有所帮助