-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Description
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):
- 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
noneonly applies when theCacheManageris auto-configured, not if it's explicitly specified. - Or,
noneshould disable caching even if there is an explicitCacheManager - Or, Spring Boot should throw an error when an explicit
CacheManageris specified andspring.cache.typeisnone Noneshould also be listed