Closed
Description
In Micronaut 1.0.2 the @Cacheable
annotation does not work on a method that returns a Publisher
.
Service Method:
@Singleton
open class HelloService {
val logger = LoggerFactory.getLogger(this.javaClass)
@Cacheable("num-cache")
@SingleResult
open fun calculateValue(num: Int): Publisher<String> {
logger.info("Calculating value for {}", num)
return Flowable.just("Hello $num")
}
}
Cache config in application.yml
micronaut:
application:
name: cacheable-sample
caches:
num-cache:
expire-after-write: 10m
Steps to Reproduce
-
run the app
./gradlew run
-
send an http request multiple times
http :8080/hello
Expected Behaviour
the method HelloService.calculateValue(0)
should only be called once, which should produce the following
output:
20:18:07.133 [nioEventLoopGroup-1-3] INFO c.s.$HelloServiceDefinition$Intercepted - Calculating value for 0
Actual Behaviour
the method is called multiple times producing the output
20:17:53.374 [nioEventLoopGroup-1-2] INFO c.s.$HelloServiceDefinition$Intercepted - Calculating value for 0
20:18:07.133 [nioEventLoopGroup-1-3] INFO c.s.$HelloServiceDefinition$Intercepted - Calculating value for 0
20:18:17.442 [nioEventLoopGroup-1-3] DEBUG i.m.c.interceptor.CacheInterceptor - Value found in cache [num-cache] for invocation: Publisher calculateValue(int num)
20:18:20.828 [nioEventLoopGroup-1-4] INFO c.s.$HelloServiceDefinition$Intercepted - Calculating value for 0
20:18:23.043 [nioEventLoopGroup-1-4] DEBUG i.m.c.interceptor.CacheInterceptor - Value found in cache [num-cache] for invocation: Publisher calculateValue(int num)
Environment Information
- Operating System: Mac OSX Mojave
- Micronaut Version: 1.0.3
- JDK Version: 1.8.0_181
Activity