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

Quarkus Cache: @CacheKey does not work on interface methods #34947

Closed
AndreasPetersen opened this issue Jul 24, 2023 · 2 comments
Closed

Quarkus Cache: @CacheKey does not work on interface methods #34947

AndreasPetersen opened this issue Jul 24, 2023 · 2 comments
Labels
area/cache area/rest-client kind/bug Something isn't working triage/invalid This doesn't seem right

Comments

@AndreasPetersen
Copy link

Describe the bug

When a @CacheResult annotated interface method has @CacheKey annotated parameters, Quarkus cache ignores the @CacheKey annotation. For example:

@RegisterRestClient
public interface MyRestClient {
    @GET
    @Path("/hello")
    String hello(
        @QueryParam("c") String c);

    @CacheResult(cacheName = "my-cache")
    default String hello(
        @CacheKey @QueryParam("a") String a, 
        @CacheKey @QueryParam("b") String b,
        @QueryParam("c") String c) {
        return hello(c);
    }
}

Expected behavior

@CacheKey is respected.

Actual behavior

@CacheKey is ignored.

cacheKeyParameterPositions in CacheInterceptor.getCacheKey is empty, thus resulting in the wrong cache key being generated.

How to Reproduce?

I have made a reproducing project here https://github.com/AndreasPetersen/quarkus-cache-key-interface/tree/main.

The project includes a MyRestClient interface with an annotated @CacheResult method with @CacheKey annotated parameters. In the GreetingResource, the cached method is called first, and then a second call is made using the Quarkus Cache programmic API, where I make a CompositeCacheKey that should match the @CacheKey annotated parameters.

A GreetingResourceTest is available, that verifies that the client REST endpoint is only called once, but the test fails because of the described bug.

Output of uname -a or ver

Linux codespaces-8fce81 5.15.0-1041-azure #48-Ubuntu SMP Tue Jun 20 20:34:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.7" 2023-04-18 LTS OpenJDK Runtime Environment Microsoft-7626293 (build 17.0.7+7-LTS) OpenJDK 64-Bit Server VM Microsoft-7626293 (build 17.0.7+7-LTS, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.16.8.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle, see reproducer project

Additional information

No response

@AndreasPetersen AndreasPetersen added the kind/bug Something isn't working label Jul 24, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 24, 2023

/cc @gwenneg (cache)

@geoand
Copy link
Contributor

geoand commented Jul 24, 2023

This has been fixed in #32406

@geoand geoand closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2023
@geoand geoand added the triage/invalid This doesn't seem right label Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cache area/rest-client kind/bug Something isn't working triage/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants