> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/31.-caching/31.1-supported-cache-providers/31.1.6-couchbase.md).

# 31.1.6 Couchbase

如果[Couchbase](https://www.couchbase.com/) Java客户端和`couchbase-spring-cache`实现可用，并且已经配置好了，`CouchbaseCacheManager`将会自动配置，使用`spring.cache.cache-names`属性可以在启动时创建其他缓存。对`Bucket`的操作也是自动配置的，你可以使用customizer在另一个`Bucket`上创建其他缓存：假设你需要在“main” `Bucket`上存放两个缓存（`cache1`和`cache2`），在另一个`Bucket`上存放一个存活时间为2秒的`cache3`缓存。首先，你通过配置创建两个缓存：

```
spring.cache.cache-names=cache1,cache2
```

然后定义其他`@Configuration`来配置另一个`Bucket`和`cache3`缓存：

```java
@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("cache3", CacheBuilder.newInstance(anotherBucket())
                    .withExpiration(2));
        };
    }

}
```

这个示例配置重用了通过自动配置的`Cluster`。
