Browse Source

Upgrade to Couchbase Cache Client 2.1.0

As of 2.1 cache expiration times are to be set in seconds. This commit
migrates to the new method, yet keeping the milliseconds unit.

Closes gh-7824
pull/7873/head
Stephane Nicoll 9 years ago
parent
commit
bf7271afa5
  1. 14
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheProperties.java
  2. 6
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java
  3. 4
      spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java
  4. 2
      spring-boot-dependencies/pom.xml
  5. 2
      spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

14
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheProperties.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.cache; @@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.cache;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
@ -146,7 +147,8 @@ public class CacheProperties { @@ -146,7 +147,8 @@ public class CacheProperties {
public static class Couchbase {
/**
* Entry expiration in milliseconds. By default the entries never expire.
* Entry expiration in milliseconds. By default the entries never expire. Note
* that this value is ultimately converted to seconds.
*/
private int expiration;
@ -154,6 +156,14 @@ public class CacheProperties { @@ -154,6 +156,14 @@ public class CacheProperties {
return this.expiration;
}
/**
* Return the expiration in seconds.
* @return the expiration in seconds
*/
public int getExpirationSeconds() {
return (int) TimeUnit.MILLISECONDS.toSeconds(this.expiration);
}
public void setExpiration(int expiration) {
this.expiration = expiration;
}

6
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -60,8 +60,8 @@ public class CouchbaseCacheConfiguration { @@ -60,8 +60,8 @@ public class CouchbaseCacheConfiguration {
public CouchbaseCacheManager cacheManager() {
List<String> cacheNames = this.cacheProperties.getCacheNames();
CouchbaseCacheManager cacheManager = new CouchbaseCacheManager(
CacheBuilder.newInstance(this.bucket).withExpirationInMillis(
this.cacheProperties.getCouchbase().getExpiration()),
CacheBuilder.newInstance(this.bucket).withExpiration(
this.cacheProperties.getCouchbase().getExpirationSeconds()),
cacheNames.toArray(new String[cacheNames.size()]));
return this.customizers.customize(cacheManager);
}

4
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -250,7 +250,7 @@ public class CacheAutoConfigurationTests { @@ -250,7 +250,7 @@ public class CacheAutoConfigurationTests {
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
Cache cache = cacheManager.getCache("foo");
assertThat(cache).isInstanceOf(CouchbaseCache.class);
assertThat(((CouchbaseCache) cache).getTtl()).isEqualTo(2000);
assertThat(((CouchbaseCache) cache).getTtl()).isEqualTo(2);
assertThat(((CouchbaseCache) cache).getNativeCache())
.isEqualTo(this.context.getBean("bucket"));
}

2
spring-boot-dependencies/pom.xml

@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
<commons-pool.version>1.6</commons-pool.version>
<commons-pool2.version>2.4.2</commons-pool2.version>
<couchbase-client.version>2.3.6</couchbase-client.version>
<couchbase-cache-client.version>2.0.0</couchbase-cache-client.version>
<couchbase-cache-client.version>2.1.0</couchbase-cache-client.version>
<crashub.version>1.3.2</crashub.version>
<derby.version>10.13.1.1</derby.version>
<dom4j.version>1.6.1</dom4j.version>

2
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

@ -4094,7 +4094,7 @@ cache: @@ -4094,7 +4094,7 @@ cache:
public CacheManagerCustomizer<CouchbaseCacheManager> cacheManagerCustomizer() {
return c -> {
c.prepareCache("biz", CacheBuilder.newInstance(anotherBucket())
.withExpirationInMillis(2000));
.withExpiration(2));
};
}

Loading…
Cancel
Save