title: How to disable Redis cache with Spring Boot?
body: <p>With Spring Boot 2.1 I am defining a RedisCacheManager bean in a configuration file, with Java configuration. Everything works correctly but I would like sometimes to disable it, for instance in the tests. Spring Boot provides the <code>spring.cache.type=NONE</code> to disable caching, as per this <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html#boot-features-caching-provider-none" rel="noreferrer">documentation</a>. However, this property will not work because I already define a CacheManager, and as such Spring Boot will not configure the NoOpCacheManager I would like there (there is a <code>@ConditionalOnMissingBean(CacheManager.class)</code> on the <code>NoOpCacheConfiguration</code> which has lower precedence than <code>RedisCacheConfiguration</code>).</p>
  
  <p>When defining caches, whatever the provider (for intance Caffeine), we usually define them as beans, which are afterwards resolved by Spring Boot's auto-configuration into a <code>SimpleCacheManager</code>. 
  For instance</p>
  
  <pre><code>    @Bean
      public Cache myCache() {
          return new CaffeineCache(
                  "my-cache",
                  Caffeine.newBuilder()
                          .maximumSize(10)
                          .build());
      }
  </code></pre>
  
  <p>Unfortunately this is not possible with Redis, because its <code>Cache</code> implementation, <code>RedisCache</code>, is not public.</p>
  
  <p>Another thing we like to do is to define a bean <code>CacheManagerCustomizer&lt;?&gt;</code>, for instance with Caffeine </p>
  
  <pre><code>    @Bean
      public CacheManagerCustomizer&lt;CaffeineCacheManager&gt; caffeineCacheManager() {
          return cacheManager -&gt; cacheManager
                  .setCaffeine(Caffeine.newBuilder()
                          .expireAfterWrite(1, TimeUnit.MINUTES));
      }
  </code></pre>
  
  <p>Again this is not possible with Redis, as <code>RedisCacheManager</code> is <strong>immutable</strong>.</p>
  
  <p>So the only solution right now is to create our own RedisCacheManager, but this prevent the usage of <code>spring.cache.type: NONE</code>.</p>
  
  <p>So here is my question. What is the best way to configure a Redis cache with Spring Boot so that we can disable it as needed ?</p>