Grails EH Cache对象作为参数问题

时间:2015-11-16 07:24:21

标签: grails ehcache

我想在我的grails应用程序中使用EHCache。我想用@Cacheable缓存一个方法。

我正在测试这种情况: 简单的测试类:

class MyTestClassB {
def a
def b

@Override
boolean equals(Object obj) {
    println ("New A" + this.a)
    println ("Olda A" + obj.a)
    if (this.a != obj.a) {
        return false
    }
    return super.equals(obj)
}
}

要在服务类中缓存的方法:

@Transactional
class HelpService {
@Cacheable('newcache')
def inlineCacheService(def param) {
    println ("I am in the function")
    MyTestClass a = new MyTestClass()
    a.paramA = new Date()
    a.paramB = [
            id: "1",
            data: "f"
    ]

    return a
}

}

所以我在控制器中调用该方法:

 MyTestClassB c1 = new MyTestClassB()
 c1.a = "paramc1"
 render "1: " + helpService.inlineCacheService(c1).paramA
 c1.a = "paramc1neu"
 render "<br/>1: " + helpService.inlineCacheService(c1).paramA

这种情况下的问题是:我更改了参数对象的值,所以我希望我没有得到缓存的值。但是,inlineCacheService的第二次调用会从缓存中读取值。这里有什么问题?我想念一些东西吗?

1 个答案:

答案 0 :(得分:0)

hashCode丢失了。实现后,缓存现在可以正常工作。感谢@ rcgeorge23 ​​

相关问题