All properties

Every property spring_boot_starter_cache reads. They configure the cacheManager bean the starter makes; when the application declares its own CacheManager (or a bean named cacheResolver), they no longer apply, except through cacheManagerFromProperties. spring.cache.resource-version is the exception: the cache interceptor reads it, whatever the manager. The starter's metadata (lib/spring_gen/spring_metadata.json) lists the same 12 keys.

Why

How long results stay fresh, how much memory or disk caches may take, and whether they outlive a restart depend on the environment: short in development, tuned in production, off in some tests, on disk in a phone app. Properties change them without a build.

Example

In memory:

# lib/resources/application.yml
spring:
  cache:
    type: simple
    cache-names: books,prices,authors
    simple:
      time-to-live: 10m
      max-size: 1000
      caches:
        prices:
          time-to-live: 30s
        "[books.byIsbn]":
          max-size: 200

The same in .properties:

# lib/resources/application.properties
spring.cache.type=simple
spring.cache.cache-names=books,prices,authors
spring.cache.simple.time-to-live=10m
spring.cache.simple.max-size=1000
spring.cache.simple.caches.prices.time-to-live=30s
spring.cache.simple.caches[books.byIsbn].max-size=200

On disk, so the results outlive a restart:

# lib/resources/application.yml
spring:
  cache:
    type: disk
    resource-version: true
    disk:
      time-to-live: 1h
      max-size: 50MB
      version: 2.1.0
      caches:
        profiles:
          time-to-live: 10m

The same in .properties:

# lib/resources/application.properties
spring.cache.type=disk
spring.cache.resource-version=true
spring.cache.disk.time-to-live=1h
spring.cache.disk.max-size=50MB
spring.cache.disk.version=2.1.0
spring.cache.disk.caches.profiles.time-to-live=10m

The properties

Key Type Default Meaning
spring.cache.type generic, simple, disk, none generic when the application has Cache beans, else simple The kind of cache manager. generic: a SimpleCacheManager of the application's Cache beans (at least one needed); simple: caches in memory (an InMemoryCacheManager); disk: caches on disk, so the entries survive a restart (a DiskCacheManager, see Caches that outlive a restart); none: caches nothing, so the methods always run (a NoOpCacheManager). Another value fails the start.
spring.cache.cache-names List<String> empty: caches are created on demand A fixed set of caches (books,authors, or a YAML list); an annotation that names another cache then fails.
spring.cache.simple.time-to-live Duration none An entry expires this long after it was written (10m, 30s, PT1H, or milliseconds), measured on a monotonic clock as Caffeine's ticker: setting the system clock moves no expiry. 0 keeps nothing; a negative value fails the start.
spring.cache.simple.max-size int none The most entries per cache; when full, the least recently used entry goes. 0 keeps nothing; a negative value fails the start.
spring.cache.simple.caches.<name>.time-to-live Duration the global one The same as spring.cache.simple.time-to-live, for this cache. A negative value fails the start.
spring.cache.simple.caches.<name>.max-size int the global one The same as spring.cache.simple.max-size, for this cache. A negative value fails the start.
spring.cache.disk.time-to-live Duration none An entry expires this long after it was written, by the wall clock, so the time counts across restarts. 0 keeps nothing; a negative value fails the start.
spring.cache.disk.caches.<name>.time-to-live Duration the global one The same as spring.cache.disk.time-to-live, for this cache. A negative value fails the start.
spring.cache.disk.max-size DataSize (50MB) none The most bytes each cache keeps; past it the oldest written go first. Only the cache's own folder counts (spring/caches/<name>/): the files the Flutter starter downloads have a limit of their own, spring.flutter.resources.cache.max-size (see Resources from the network).
spring.cache.disk.directory folder .spring/cache in the working folder Where the entries go when no CacheStore bean gives a place: a server, a program without Flutter. A Flutter app keeps them in its files' cache place, and the key does nothing there.
spring.cache.disk.version text none: every entry is read The version entries are written by; an entry of another version is not read, so results made from what a new version changed are made again.
spring.cache.resource-version bool false Whether a key made of a resource that knows the version of its content (a file the Flutter starter keeps) is its address and that version, so a result made from a file that changed at the same address is made again. Applies to every type, to the keys of SimpleKeyGenerator (an operation without key or keyGenerator). Off by default: the version is a digest of the whole file.
spring.main.startup-checks.enabled bool not set: debug and profile builds Read by the generator, not at run time: whether the cacheOperationValidator startup check is in the build. true: in every build. false: in none. Not set: in debug and profile builds only; a release build ships none of its code, and a wrong annotation fails at the member's first call.

The simple.* keys apply to type=simple, the disk.* keys to type=disk. Every per-cache value is checked at the start, whether the cache exists yet or not.

Writing values

In Spring (Java)

spring.cache.type and spring.cache.cache-names are Spring Boot's. Here type knows generic, simple, disk and none (no caffeine, redis, jcache...), and disk is this starter's own. spring.cache.simple.*, spring.cache.disk.* and spring.cache.resource-version are this starter's too: Spring Boot's simple type has no settings, the time to live and size come from spring.cache.caffeine.spec or spring.cache.redis.* there, and results outlive a restart in a store such as Redis.

See also