Skip to content

Improve documentation of spring.cache.type=none #33694

@micheljung

Description

@micheljung

Summary

The doc can be interpreted such that spring.cache.type=none disables caching, when in fact it's not really what it does. The documentation or behavior of Spring Boot should be improved in this regard.

Details

If you want to disable caching, you'll quickly find this in the documentation:

When @EnableCaching is present in your configuration, a suitable cache configuration is expected as well. If you need to disable caching altogether in certain environments, force the cache type to none to use a no-op implementation, as shown in the following example:

spring.cache.type=none

So you do that and think your caching is disabled but if you have an explicit CacheManager configured, it is not. This is because all cache configs are @Conditional({ CacheCondition.class }) and @ConditionalOnMissingBean(CacheManager.class).

Therefore, if you specify spring.cache.type=none, all that happens is that NoOpCacheConfiguration will be loaded if there is no CacheManager bean.

This is partially explained in the docs:

If you have not defined a bean of type CacheManager or a CacheResolver named cacheResolver (see CachingConfigurer), Spring Boot tries to detect the following providers (in the indicated order):

  1. Generic
  2. JCache (JSR-107) (EhCache 3, Hazelcast, Infinispan, and others)
  3. Hazelcast
  4. Infinispan
  5. Couchbase
  6. Redis
  7. Caffeine
  8. Cache2k
  9. Simple

In this list, None is missing, even though NoOpCacheConfiguration is also considered, further contributing to the confusion.

I think that:

  1. The doc should make very clear that none only applies when the CacheManager is auto-configured, not if it's explicitly specified.
  2. Or, none should disable caching even if there is an explicit CacheManager
  3. Or, Spring Boot should throw an error when an explicit CacheManager is specified and spring.cache.type is none
  4. None should also be listed

Metadata

Metadata

Assignees

Labels

status: feedback-reminderWe've sent a reminder that we need additional information before we can continuestatus: waiting-for-feedbackWe need additional information before we can continuetype: documentationA documentation update

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions