Configuring Caches

By default, Caffeine is used to create caches from application configuration. For example with application.yml:

Cache Configuration Example

  1. micronaut:
  2. caches:
  3. my-cache:
  4. maximum-size: 20

The above example configures a cache called “my-cache” with a maximum size of 20.

Naming Caches

Define names of caches under micronaut.caches in kebab case (lowercase and hyphen separated); if you use camel case, the names are normalized to kebab case. For example myCache becomes my-cache. The kebab-case form must be used when referencing caches in the @Cacheable annotation.

To configure a weigher to be used with the maximumWeight configuration, create a bean that implements io.micronaut.caffeine.cache.Weigher. To associate a given weigher with only a specific cache, annotate the bean with @Named(<cache name>). Weighers without a named qualifier apply to all caches that don’t have a named weigher. If no beans are found, a default implementation is used.

See the configuration reference for all available configuration options.