Search code examples
javacachingredismicronaut

Why don't items expire in my Micronaut/Redis cache?


I have a Micronaut cache in Redis configured like this:

redis:
  uri: ${REDIS_URL:`redis://localhost`}
  caches:
    kyc-fenergo-service-token:
      expire-after-write: 14m

I have a method annotated like this: @Cacheable(value = "kyc-fenergo-service-token")

After the first call, the value is cached as expected, but it never expires. Any idea why this is the case?


Solution

  • Check your Redis server configuration to ensure that key expiration is enabled. Look for the notify-keyspace-events configuration directive in your Redis configuration file (redis.conf) and make sure it includes the Ex flag. For example, notify-keyspace-events Ex.