grails-cache icon indicating copy to clipboard operation
grails-cache copied to clipboard

Can not update cache with the same key

Open 112921482 opened this issue 7 years ago • 4 comments

@Cacheable(value="token",key = { 1000 }) def getToken(){ this.updateToken() }

@CachePut(value="token",key = {1000}) def updateToken(){ // some code get a result ******* // some code get a result return result; }

"getToken" can not get the same after I run updateToken

112921482 avatar Aug 24 '17 12:08 112921482

Please upload an example application that reproduces the issue. Also what version?

jameskleeh avatar Oct 18 '17 14:10 jameskleeh

The problem is that in version 4.0.0 of cache plugin the actual key in cache is CustomCacheKeyGenerator$TemporaryGrailsCacheKey - which in addition to simpleKey field (the key specified in @Cacheable annotation - in this case 1000) also contains targetClassName field and targetMethodName field (which in this case is 'getToken').

@CachePut nor @CacheEvict annotations could know what is the actual key in cache, since they don't know the name of method on which @Cacheable annotation was applied.

verglor avatar May 07 '18 18:05 verglor

@112921482 and @verglor : you could check if your problem is solved with the manual key comparison in my merge request #51

mkobel avatar May 13 '18 11:05 mkobel

@112921482 and @verglor the merge request #51 is merged into master with 13f8b0556873e8cf7df4511094a3c517d75cc61b so you could try if this solves your problem.

mkobel avatar May 31 '18 18:05 mkobel