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:
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):
- Generic
- JCache (JSR-107) (EhCache 3, Hazelcast, Infinispan, and others)
- Hazelcast
- Infinispan
- Couchbase
- Redis
- Caffeine
- Cache2k
- Simple
In this list, None is missing, even though NoOpCacheConfiguration is also considered, further contributing to the confusion.
I think that:
- The doc should make very clear that
none only applies when the CacheManager is auto-configured, not if it's explicitly specified.
- Or,
none should disable caching even if there is an explicit CacheManager
- Or, Spring Boot should throw an error when an explicit
CacheManager is specified and spring.cache.type is none
None should also be listed
Summary
The doc can be interpreted such that
spring.cache.type=nonedisables 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:
So you do that and think your caching is disabled but if you have an explicit
CacheManagerconfigured, 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 thatNoOpCacheConfigurationwill be loaded if there is noCacheManagerbean.This is partially explained in the docs:
In this list,
Noneis missing, even thoughNoOpCacheConfigurationis also considered, further contributing to the confusion.I think that:
noneonly applies when theCacheManageris auto-configured, not if it's explicitly specified.noneshould disable caching even if there is an explicitCacheManagerCacheManageris specified andspring.cache.typeisnoneNoneshould also be listed