Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Ignore @Cacheable Annotation on Controller Methods #208

Open
wants to merge 1 commit into
base: 4.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ grails-app/conf/BootStrap.groovy
grails-app/conf/spring/
grails-app/views/error.gsp
grails-app/views/index.gsp
bin/
7 changes: 7 additions & 0 deletions grails-app/controllers/com/demo/DemoController.groovy
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.demo

import grails.plugin.cache.Cacheable

class DemoController {

def basicCachingService
def grailsCacheAdminService

@Cacheable('show')
def show (params) {
return [param: params.id]
}

def clearBlocksCache() {
grailsCacheAdminService.clearBlocksCache()
render "cleared blocks cache"
Expand Down
1 change: 1 addition & 0 deletions grails-app/views/demo/show.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!${param}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class CacheableTransformation extends AbstractCacheTransformation {
@Override
protected Expression buildDelegatingMethodCall(SourceUnit sourceUnit, AnnotationNode annotationNode, ClassNode classNode, MethodNode methodNode, MethodCallExpression originalMethodCallExpr, BlockStatement newMethodBody) {

boolean isControllerClass = classNode.name.endsWith('Controller')
boolean isServiceClass = classNode.name.endsWith('Service')

if (isControllerClass && !isServiceClass) {
return originalMethodCallExpr
}

VariableExpression cacheManagerVariableExpression = varX(GRAILS_CACHE_MANAGER_PROPERTY_NAME)
handleCacheCondition(sourceUnit, annotationNode, methodNode, originalMethodCallExpr, newMethodBody)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.demo

import geb.spock.GebSpec
import grails.testing.mixin.integration.Integration

@Integration
class NotCachingControllerIntegrationSpec extends GebSpec {

void 'test action controller with different parameters'() {
when:
go '/demo/show/1'

then:
$().text().contains 'Hello World!1'

when:
go '/demo/show/2'

then:
$().text().contains 'Hello World!2'
}
}