I'm using Spring Boot 1.5.12.RELEASE
, with caffeine 2.6.2
as caching provider.
I have a method in one of my services:
@Cacheable(cacheNames = [CacheService.MY_CACHE_NAME], sync = true)
fun fetchThing(id: Int, at: OffsetDateTime?): Thing? {
LOGGER.debug("################### $id $at #############")
// some network operation
LOGGER.debug("################### $id $at IS DONE #############")
return thing
}
I'd expect to see the first log only once, but if I call fetchThing
again before the first call resolved, the value is computed two times:
09:18:34.657 [XNIO-2 task-11] DEBUG c.a.n.i.thing.ThingService - ################### 3140 null #############
09:18:34.673 [XNIO-2 task-12] DEBUG c.a.n.i.thing.ThingService - ################### 3140 null #############
09:18:36.025 [XNIO-2 task-11] DEBUG c.a.n.i.thing.ThingService - ################### 3140 null IS DONE #############
09:18:36.030 [XNIO-2 task-12] DEBUG c.a.n.i.thing.ThingService - ################### 3140 null IS DONE #############
If I call this function again I don't see any logs so the caching is working.
So it seems that sync
is not working.
Am I missing something?
EDIT: main class annotations:
@SpringBootApplication(exclude = [ElastiCacheAutoConfiguration::class])
@EnableSwagger2
@EnableScheduling
@EnableCaching
@EnableTransactionManagement
class Application