Any plans to integrate Couchbase 2.x with Spring cache? Any help would be appreciated.
Itâs been separated in its own project (so that it is not tied to longer Spring Data release cycles) in our github: couchbaselabs/couchbase-spring-cache.
For now itâs still in development. A version should be released and deployed to Maven Central soon, but you can certainly play around with it by building the master with Maven if youâre so inclined.
Feedback welcome!!
Do we have release target date on this?
I love to contribute if you need help.
thereâs no release target date yet, as weâre working with StĂ©phane Nicoll (the Spring Boot lead) in order to improve the implementation for a great integration into Spring Boot, right from the start.
when thatâs stabilized a little, then a 2.0.0 release will be quick to come.
That said, Spring Cache is pretty straightforward (a couple classes), and works in the current state even if thereâs still room for improvement (weird CacheManager constructor, no dynamic creation of caches), so you could start using it, if youâre ok with changing configuration code later on when this hits GAâŠ
I could tag the current state as 2.0.0.M1
, mark it as a pre-release in Github (and probably attach the jar to the release), if that helps?
Can you please help me how i can configure com.couchbase.client.spring.cache.CouchbaseCacheManager in XML
I am trying to migrate from Couchbase client (using Spring cache) to Java client and i would like to keep Spring cache support with @Cacheable.
I donât understand your last sentence? Whatâs the âCouchbase clientâ and whatâs the âJava clientâ?
In order to use the CouchbaseCacheManager
and configure it in xml, youâll need:
- the common xml setup of spring cache (see documentation)
- a Couchbase
Bucket
as a bean in your context (so you need to open it from aCluster
, itâs a little more involved in xml) - declare a
CacheBuilder
bean - declare a
CouchbaseCacheManager
bean
Here is an example of all those couchbase-related beans:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="couchbaseCluster" class="com.couchbase.client.java.CouchbaseCluster" factory-method="create">
<constructor-arg>
<list>
<!-- list the IP/hostnames to bootstrap from (recommended: 2) -->
<value>127.0.0.1</value>
</list>
</constructor-arg>
</bean>
<bean id="couchbaseBucket" class="com.couchbase.client.java.Bucket"
factory-bean="couchbaseCluster" factory-method="openBucket">
<!-- specify the bucket and password to use -->
<constructor-arg index="0" type="java.lang.String" value="default"/>
<constructor-arg index="1" type="java.lang.String" value=""/>
</bean>
<bean id="couchbaseCacheBuilder" class="com.couchbase.client.spring.cache.CacheBuilder"
factory-method="newInstance">
<constructor-arg type="com.couchbase.client.java.Bucket" ref="couchbaseBucket"/>
</bean>
<bean id="cacheManager" class="com.couchbase.client.spring.cache.CouchbaseCacheManager">
<constructor-arg type="com.couchbase.client.spring.cache.CacheBuilder" ref="couchbaseCacheBuilder"/>
<constructor-arg>
<list>
<!-- pre-declare caches you intend to use -->
<value>staticCache1</value>
<value>staticCache2</value>
<value>staticCache3</value>
</list>
</constructor-arg>
</bean>
</beans>
I added an integration test to demonstrate that in the master branch
@babu.maganti / @bmaganti I would still consider wiring all that through a @Configuration
annotated class (java config). It can get complicated in xml if you want to tune the SDKâs Cluster
.
Side-note: You probably saw that there was a first release on Maven Central?
Yes, i saw the 2.0.0 release.
I am not sure why you didnât use couchbase xsd.
Anyway thank you for your inputs.
I will update you once i completeâŠ
In between, i have two caches setup
- Couchbase
- JVM using Ehcache
I am not sure how this XML config will work with Ehcache config
Thank you so much @simonbasle ⊠Its working like charm.
@simonbasle - Do you happens to know where i can see Spring Data and Spring Cache example with Client 2?
A demo application is on our radar, but I donât have a roadmap for it yet
In the meantime I recommend looking at the tests, even though itâs not ideal in terms of finding a particular information, or look at the documentation topics.
@simonbasle - I am seeing following error⊠any idea?
Failed to instantiate [com.couchbase.client.java.Bucket]: Factory method âopenBucketâ threw exception; nested exception is java.lang.RuntimeException: java.util.concurrent.TimeoutException
Maybe the Couchbase cluster is on another machine with network latency? Can you try pinging the couchbase server machine from the machine where the client runs?
Weâve also seen cases where connecting to a node the first time would take a long time (or even timeout) on Windows.
The Cluster
can be created with a CouchbaseEnvironment
, which in turn allows you to tune the connectTimeout
(in milliseconds). But once again, this is getting tricky with XML configuration
I am checking if there is issues with our deployment process⊠because its working some times and its throwing error other times.
And i am tuning the timeout as well.
By the way we didnât see this issue with Couchbase Client 1
We are migrated from Couchbase Client to JDK 2 client. and we are seeing this issue.
Increased CB timeout to 3mins and i am not seeing the error.