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

`@CacheEvict` & CompileStatic errors for key closures

Open jdaugherty opened this issue 2 months ago • 2 comments

Issue description

The following code worked in Grails 6 on a class annotated with @CompileStatic

    @CacheEvict(value = "apiTokens", key = { token })
    void deleteByToken(String token) {

In Grails 7, this fails with:

   [Static type checking] - The variable [token] is undeclared.

jdaugherty avatar Oct 30 '25 04:10 jdaugherty

As a work around @CompileDynamic can be added and this will work...

jdaugherty avatar Oct 30 '25 04:10 jdaugherty

I think I ran into the same issue, had to use arg# instead of parameter name:

-    @Cacheable(cacheNames = ES_CACHE_NAME, key = "{#request.myField, #request.SsomeOtherField}")
+    @Cacheable(cacheNames = ES_CACHE_NAME, key = "{#a0.myField, #a0.someOtherField}")

dauer avatar Nov 03 '25 15:11 dauer