1

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
andrew
  • 3,879
  • 4
  • 25
  • 43

1 Answers1

0

It is ridiculous, but... try to change the cache name.

I've just had the same problem and had no idea what's wrong in my config. So I've changed the name of the cache - it magically worked. So silly...

Zefr
  • 11
  • 2