Couchbase Spring Cache

Spring Cache implementation based on the official Couchbase Java SDK

License

License

Categories

Categories

Couchbase Data Databases CLI User Interface
GroupId

GroupId

com.couchbase.client
ArtifactId

ArtifactId

couchbase-spring-cache
Last Version

Last Version

2.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Couchbase Spring Cache
Spring Cache implementation based on the official Couchbase Java SDK
Project URL

Project URL

https://github.com/couchbaselabs/couchbase-spring-cache
Project Organization

Project Organization

Couchbase, Inc.
Source Code Management

Source Code Management

https://github.com/couchbaselabs/couchbase-spring-cache

Download couchbase-spring-cache

How to add to project

<!-- https://jarcasting.com/artifacts/com.couchbase.client/couchbase-spring-cache/ -->
<dependency>
    <groupId>com.couchbase.client</groupId>
    <artifactId>couchbase-spring-cache</artifactId>
    <version>2.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.couchbase.client/couchbase-spring-cache/
implementation 'com.couchbase.client:couchbase-spring-cache:2.1.0'
// https://jarcasting.com/artifacts/com.couchbase.client/couchbase-spring-cache/
implementation ("com.couchbase.client:couchbase-spring-cache:2.1.0")
'com.couchbase.client:couchbase-spring-cache:jar:2.1.0'
<dependency org="com.couchbase.client" name="couchbase-spring-cache" rev="2.1.0">
  <artifact name="couchbase-spring-cache" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.couchbase.client', module='couchbase-spring-cache', version='2.1.0')
)
libraryDependencies += "com.couchbase.client" % "couchbase-spring-cache" % "2.1.0"
[com.couchbase.client/couchbase-spring-cache "2.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.springframework : spring-context jar
com.couchbase.client : java-client jar 2.3.6
org.slf4j : slf4j-api jar 1.7.10

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.hamcrest : hamcrest-core jar 1.3
org.springframework : spring-test jar

Project Modules

There are no modules declared in this project.

couchbase-spring-cache


IMPORTANT: Spring Cache support has been merged with spring-data-couchbase: https://github.com/spring-projects/spring-data-couchbase. Just import spring-data-couchbase and you will find the spring cache modules under the org.springframework.data.couchbase.cache namespace!


An implementation for Spring Cache based on Couchbase Java SDK 2.x

Suitable to work with Spring Data Couchbase 2.0.x and above, as the two projects can share the same backing SDK Cluster and Buckets. This is especially awesome for Spring Boot apps (both Spring Data Couchbase and Couchbase Spring Cache are included in Spring Boot 1.4.0 and up).

Usage

Instantiate a CouchbaseCacheManager using CacheBuilder to either create several caches sharing the same template or a map of builders to individually customize several preloaded caches.

//preloaded cache manager, same configs
new CouchbaseCacheManager(new CacheBuilder().withBucket(bucket), "cache1", "cache2");

//preloaded cache manager, custom configs
Map<String, CacheBuilder> caches = new HashMap<String, CacheBuilder>();
caches.put("cacheA", new CacheBuilder().withBucket(bucket).withExpirationInMillis(2000));
caches.put("cacheB", new CacheBuilder().withBucket(bucket2).withExpirationInMillis(3000));
new CouchbaseCacheManager(caches);

//dynamic-capable cache manager
//no cache is preloaded but it will create them on demand using the builder as a template
new CouchbaseCacheManager(new CacheBuilder().withBucket(bucket).withExpirationInMillis(1000));

Notice how the CacheBuilder allows you to describe how the Cache is backed by Couchbase by providing a Bucket from the Couchbase Java SDK, among other tunings.

Note that for now only buckets of type "couchbase" are supported, so that several caches can be created over the same Bucket and still cleared independently.

How to get it: how to build

Release 2.0.0 is available on Maven Central. Edit your pom.xml and add the following dependency in the dependencies section:

<dependency>
    <groupId>com.couchbase.client</groupId>
    <artifactId>couchbase-spring-cache</artifactId>
    <version>2.1.0</version>
</dependency>

You can also build the latest snapshot yourself from master:

git clone https://github.com/couchbaselabs/couchbase-spring-cache.git
cd couchbase-spring-cache
mvn clean install

Background, why a 2.x version?

This was historically part of Spring Data Couchbase up until the 2.0.0 version, which was rewritten to use the Java SDK 2.x. The project was then extracted so that it could be reworked on top of the same SDK, while not being strongly tied to Spring Data (which can have longer release cycles).

This also allows for a rework of the initial 2.0.0 API, with tight feedback from the Spring Boot project, so that it can be well integrated into Spring Boot.

com.couchbase.client

Couchbase Labs

Versions

Version
2.1.0
2.0.0