Add Couchbase cache support
This commit updates the cache auto-configuration to provide a `CouchbaseCacheManager` if a `Bucket` has been configured. The global customizer infrastructure allows to further tune the cache manager if necessary. Closes gh-5176
This commit is contained in:
@@ -64,6 +64,7 @@ content into your application; rather pick only the properties that you need.
|
||||
# SPRING CACHE ({sc-spring-boot-autoconfigure}/cache/CacheProperties.{sc-ext}[CacheProperties])
|
||||
spring.cache.cache-names= # Comma-separated list of cache names to create if supported by the underlying cache manager.
|
||||
spring.cache.caffeine.spec= # The spec to use to create caches. Check CaffeineSpec for more details on the spec format.
|
||||
spring.cache.couchbase.expiration=0 # Entry expiration in milliseconds. By default the entries never expire.
|
||||
spring.cache.ehcache.config= # The location of the configuration file to use to initialize EhCache.
|
||||
spring.cache.guava.spec= # The spec to use to create caches. Check CacheBuilderSpec for more details on the spec format.
|
||||
spring.cache.hazelcast.config= # The location of the configuration file to use to initialize Hazelcast.
|
||||
|
||||
@@ -3311,6 +3311,7 @@ providers (in this order):
|
||||
* <<boot-features-caching-provider-ehcache2,EhCache 2.x>>
|
||||
* <<boot-features-caching-provider-hazelcast,Hazelcast>>
|
||||
* <<boot-features-caching-provider-infinispan,Infinispan>>
|
||||
* <<boot-features-caching-provider-couchbase,Couchbase>>
|
||||
* <<boot-features-caching-provider-redis,Redis>>
|
||||
* <<boot-features-caching-provider-caffeine,Caffeine>>
|
||||
* <<boot-features-caching-provider-guava,Guava>>
|
||||
@@ -3320,8 +3321,8 @@ It is also possible to _force_ the cache provider to use via the `spring.cache.t
|
||||
property.
|
||||
|
||||
If the `CacheManager` is auto-configured by Spring Boot, you can further tune its
|
||||
configuration before it is fully initialized by exposing a bean implementing the
|
||||
`CacheManagerCustomizer` interface. The following set the cache names to use.
|
||||
configuration before it is fully initialized by exposing a bean implementing the
|
||||
`CacheManagerCustomizer` interface. The following sets the cache names to use.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@@ -3433,6 +3434,56 @@ Caches can be created on startup via the `spring.cache.cache-names` property. If
|
||||
|
||||
|
||||
|
||||
[[boot-features-caching-provider-couchbase]]
|
||||
==== Couchbase
|
||||
If Couchbase is available and <<boot-features-couchbase,configured>>, a
|
||||
`CouchbaseCacheManager` is auto-configured. It is also possible to create additional
|
||||
caches on startup using the `spring.cache.cache-names` property. These will operate on
|
||||
the `Bucket` that was auto-configured. You can _also_ create additional caches on another
|
||||
`Bucket` using the customizer: assume you need two caches on the "main" `Bucket` (`foo`
|
||||
and `bar`) and one `biz` cache with a custom time to live of 2sec on the `another`
|
||||
`Bucket`. First, you can create the two first caches simply via configuration:
|
||||
|
||||
[source,properties,indent=0]
|
||||
----
|
||||
spring.cache.cache-names=foo,bar
|
||||
----
|
||||
|
||||
Then define this extra `@Configuration` to configure the extra `Bucket` and the `biz`
|
||||
cache:
|
||||
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Configuration
|
||||
public class CouchbaseCacheConfiguration {
|
||||
|
||||
private final Cluster cluster;
|
||||
|
||||
public CouchbaseCacheConfiguration(Cluster cluster) {
|
||||
this.cluster = cluster;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Bucket anotherBucket() {
|
||||
return this.cluster.openBucket("another", "secret");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CacheManagerCustomizer<CouchbaseCacheManager> cacheManagerCustomizer() {
|
||||
return c -> {
|
||||
c.prepareCache("biz", CacheBuilder.newInstance(anotherBucket())
|
||||
.withExpirationInMillis(2000));
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
This sample configuration reuses the `Cluster` that was created via auto-configuration.
|
||||
|
||||
|
||||
|
||||
[[boot-features-caching-provider-redis]]
|
||||
==== Redis
|
||||
If Redis is available and configured, the `RedisCacheManager` is auto-configured. It is
|
||||
|
||||
Reference in New Issue
Block a user