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

Conversation

jsolas
Copy link

@jsolas jsolas commented Jun 22, 2024

Related Issue:
This PR addresses the issue described in #168

Summary
This PR addresses an issue where the @Cacheable annotation on controller methods does not behave as expected in plugin version 4.0.0. Instead of ignoring the annotation, the method is executed only the first time as if it were being cached, causing inconsistencies when the controller action receives parameters.

Solution
To solve this issue, I have modified the buildDelegatingMethodCall method to check if the class is a controller and not a service. If it is a controller, the original method call is returned, effectively ignoring the @Cacheable annotation.

Here is the relevant code snippet:

@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
    }

    // Existing logic for handling caching
}

Reason for Targeting the 4.x Branch
I am submitting this change to the 4.x branch because I encountered this issue when migrating from Grails 2.5.6 to Grails 3.3.11, where I started using version 4 of the cache plugin.

@CLAassistant
Copy link

CLAassistant commented Jun 22, 2024

CLA assistant check
All committers have signed the CLA.

@jsolas jsolas changed the title Ignore caching in controllers Fix: Ignore @Cacheable Annotation on Controller Methods Jun 22, 2024
currently when caching a method in a controller the parameter is ignored and returns the same result for all calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants