quarkus: CacheResult not working in extension

Describe the bug

I’m writing an extension and I needed data caching for a method, so I tried using @CacheResult from quarkus-cache. When the method gets called, this exception occurs:

java.util.NoSuchElementException: No value present
        at java.base/java.util.Optional.get(Optional.java:148)
        at io.quarkus.cache.runtime.CacheResultInterceptor.intercept(CacheResultInterceptor.java:39)
        at io.quarkus.cache.runtime.CacheResultInterceptor_Bean.intercept(CacheResultInterceptor_Bean.zig:330)
        at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
        at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)

And the method body is never reached. I followed the cache tutorial here and I’m using the same exact code.

I’m kinda new to quarkus so this could very well be a configuration error on my part, apologies in advance.

Expected behavior

When executing the intercept method in CacheResultInterceptor, the cache manager contains a list of all the caches declared by the CacheResult annotations present in the application.

Actual behavior

In the interceptor, the cache manager’s list of caches is empty, so when it tries to retrieve one by name, the NoSuchElementException occurs.

How to Reproduce?

No response

Output of uname -a or ver

Linux 5.11.0-27-generic #29~20.04.1-Ubuntu SMP Wed Aug 11 15:58:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version “11.0.12” 2021-07-20 OpenJDK Runtime Environment GraalVM CE 21.2.0 (build 11.0.12+6-jvmci-21.2-b08) OpenJDK 64-Bit Server VM GraalVM CE 21.2.0 (build 11.0.12+6-jvmci-21.2-b08, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.1.3.Final

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

Apache Maven 3.8.1

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (18 by maintainers)

Most upvoted comments

I should’ve fixed it now, sorry

Thanks!

I knew my question wasn’t competely clear 😄 I’ll try to explain better.

This is the quarkus-cache feature that’s not working. It is used from the runtime module the quarkus-security-extension.

@CacheResult won’t work in @Crunchy-Muesli’s project because CacheProcessor is never executed and therefore CacheResultInterceptor can’t find the cache that was never built at Quarkus build time.

So, if:

  • extension A offers a feature F which requires build time processing and bytecode recording to work properly
  • extension B depends on A
  • B uses F in its own runtime module
  • application C depends on B but never uses F in its code

Should the @BuildSteps from A be executed when C is built? Because they’re not in @Crunchy-Muesli’s example and that leads to the exception mentioned above.