diff --git a/pom.xml b/pom.xml
index dbd450922..22122c096 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
3.5.9
2.23.1
2.0.12
- 2.6.0
+ 3.10.8
5.10.2
2.13.1
@@ -79,10 +79,16 @@
${slf4j.version}
- net.sf.ehcache
- ehcache-core
+ org.ehcache
+ ehcache
${ehcache.version}
+ org.glassfish.jaxb is blocked in maven 3.8.1 as it comes from http (not https) repository.
+ Also, it is not required in java 8 so we excluded it. See https://github.com/ehcache/ehcache3/issues/2881. -->
+
+ org.glassfish.jaxb
+ jaxb-runtime
+
org.slf4j
slf4j-api
diff --git a/src/main/java/net/spy/memcached/ConnectionFactoryBuilder.java b/src/main/java/net/spy/memcached/ConnectionFactoryBuilder.java
index 02e5f42e5..79d209287 100644
--- a/src/main/java/net/spy/memcached/ConnectionFactoryBuilder.java
+++ b/src/main/java/net/spy/memcached/ConnectionFactoryBuilder.java
@@ -79,9 +79,6 @@ public class ConnectionFactoryBuilder {
private int maxFrontCacheElements = DefaultConnectionFactory.DEFAULT_MAX_FRONTCACHE_ELEMENTS;
private int frontCacheExpireTime = DefaultConnectionFactory.DEFAULT_FRONTCACHE_EXPIRETIME;
private String frontCacheName = "ArcusFrontCache_" + this.hashCode();
- private boolean frontCacheCopyOnRead = DefaultConnectionFactory.DEFAULT_FRONT_CACHE_COPY_ON_READ;
- private boolean frontCacheCopyOnWrite =
- DefaultConnectionFactory.DEFAULT_FRONT_CACHE_COPY_ON_WRITE;
private int maxSMGetChunkSize = DefaultConnectionFactory.DEFAULT_MAX_SMGET_KEY_CHUNK_SIZE;
private byte delimiter = DefaultConnectionFactory.DEFAULT_DELIMITER;
@@ -347,16 +344,16 @@ public ConnectionFactoryBuilder setFrontCacheExpireTime(int to) {
/**
* Set front cache copyOnRead property
*/
+ @Deprecated
public ConnectionFactoryBuilder setFrontCacheCopyOnRead(boolean copyOnRead) {
- frontCacheCopyOnRead = copyOnRead;
return this;
}
/**
* Set front cache copyOnWrite property
*/
+ @Deprecated
public ConnectionFactoryBuilder setFrontCacheCopyOnWrite(boolean copyOnWrite) {
- frontCacheCopyOnWrite = copyOnWrite;
return this;
}
@@ -616,13 +613,17 @@ public String getFrontCacheName() {
}
@Override
+ @SuppressWarnings("deprecation")
+ @Deprecated
public boolean getFrontCacheCopyOnRead() {
- return frontCacheCopyOnRead;
+ return DefaultConnectionFactory.DEFAULT_FRONT_CACHE_COPY_ON_READ;
}
@Override
+ @SuppressWarnings("deprecation")
+ @Deprecated
public boolean getFrontCacheCopyOnWrite() {
- return frontCacheCopyOnWrite;
+ return DefaultConnectionFactory.DEFAULT_FRONT_CACHE_COPY_ON_WRITE;
}
@Override
diff --git a/src/main/java/net/spy/memcached/DefaultConnectionFactory.java b/src/main/java/net/spy/memcached/DefaultConnectionFactory.java
index 2d92d0f8a..4c6579832 100644
--- a/src/main/java/net/spy/memcached/DefaultConnectionFactory.java
+++ b/src/main/java/net/spy/memcached/DefaultConnectionFactory.java
@@ -134,13 +134,17 @@ public class DefaultConnectionFactory extends SpyObject
"ArcusFrontCache" + new Object().hashCode();
/**
+ * copyOnRead is no longer used
* Default copyOnRead : false
*/
+ @Deprecated
public static final boolean DEFAULT_FRONT_CACHE_COPY_ON_READ = false;
/**
+ * copyOnWrite is no longer used
* Default copyOnWrite : false
*/
+ @Deprecated
public static final boolean DEFAULT_FRONT_CACHE_COPY_ON_WRITE = false;
/**
@@ -347,11 +351,13 @@ public String getFrontCacheName() {
}
@Override
+ @Deprecated
public boolean getFrontCacheCopyOnRead() {
return DEFAULT_FRONT_CACHE_COPY_ON_READ;
}
@Override
+ @Deprecated
public boolean getFrontCacheCopyOnWrite() {
return DEFAULT_FRONT_CACHE_COPY_ON_WRITE;
}
diff --git a/src/main/java/net/spy/memcached/plugin/FrontCacheMemcachedClient.java b/src/main/java/net/spy/memcached/plugin/FrontCacheMemcachedClient.java
index 84807dcb4..b8bfea81a 100644
--- a/src/main/java/net/spy/memcached/plugin/FrontCacheMemcachedClient.java
+++ b/src/main/java/net/spy/memcached/plugin/FrontCacheMemcachedClient.java
@@ -66,13 +66,8 @@ public FrontCacheMemcachedClient(ConnectionFactory cf,
String cacheName = cf.getFrontCacheName();
int maxElements = cf.getMaxFrontCacheElements();
int timeToLiveSeconds = cf.getFrontCacheExpireTime();
- boolean copyOnRead = cf.getFrontCacheCopyOnRead();
- boolean copyOnWrite = cf.getFrontCacheCopyOnWrite();
- // TODO add an additional option
- // int timeToIdleSeconds = timeToLiveSeconds;
- localCacheManager = new LocalCacheManager(cacheName, maxElements,
- timeToLiveSeconds, copyOnRead, copyOnWrite);
+ localCacheManager = new LocalCacheManager(cacheName, maxElements, timeToLiveSeconds);
}
}
diff --git a/src/main/java/net/spy/memcached/plugin/LocalCacheManager.java b/src/main/java/net/spy/memcached/plugin/LocalCacheManager.java
index da0569435..d199e7aa2 100644
--- a/src/main/java/net/spy/memcached/plugin/LocalCacheManager.java
+++ b/src/main/java/net/spy/memcached/plugin/LocalCacheManager.java
@@ -16,6 +16,7 @@
*/
package net.spy.memcached.plugin;
+import java.time.Duration;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -24,52 +25,39 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
-import net.sf.ehcache.Cache;
-import net.sf.ehcache.CacheManager;
-import net.sf.ehcache.Element;
-import net.sf.ehcache.config.CacheConfiguration;
-import net.sf.ehcache.config.PersistenceConfiguration;
-import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
-
import net.spy.memcached.compat.log.Logger;
import net.spy.memcached.compat.log.LoggerFactory;
+import org.ehcache.Cache;
+import org.ehcache.CacheManager;
+import org.ehcache.config.CacheConfiguration;
+import org.ehcache.config.builders.CacheConfigurationBuilder;
+import org.ehcache.config.builders.CacheManagerBuilder;
+import org.ehcache.config.builders.ExpiryPolicyBuilder;
+import org.ehcache.config.builders.ResourcePoolsBuilder;
+
/**
* Local cache storage based on ehcache.
*/
public class LocalCacheManager {
private Logger logger = LoggerFactory.getLogger(getClass());
-
- protected Cache cache;
+ private Cache cache;
protected String name;
- public LocalCacheManager(String name) {
+ public LocalCacheManager(String name, int max, int exptime) {
this.name = name;
- // create a undecorated Cache object.
- this.cache = CacheManager.getInstance().getCache(name);
- }
-
- public LocalCacheManager(String name, int max, int exptime, boolean copyOnRead,
- boolean copyOnWrite) {
- this.cache = CacheManager.getInstance().getCache(name);
- if (cache == null) {
- CacheConfiguration config =
- new CacheConfiguration(name, max)
- .copyOnRead(copyOnRead)
- .copyOnWrite(copyOnWrite)
- .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
- .eternal(false)
- .timeToLiveSeconds(exptime)
- .timeToIdleSeconds(exptime)
- .diskExpiryThreadIntervalSeconds(60)
- .persistence(new PersistenceConfiguration().strategy(
- PersistenceConfiguration.Strategy.NONE));
- this.cache = new Cache(config, null, null);
- CacheManager.getInstance().addCache(cache);
-
- logger.info("Arcus k/v local cache is enabled : %s", cache.toString());
- }
+ CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
+ .build(true);
+ CacheConfiguration config =
+ CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, Object.class,
+ ResourcePoolsBuilder.heap(max))
+ .withExpiry(ExpiryPolicyBuilder
+ .timeToLiveExpiration(Duration.ofSeconds(exptime)))
+ .build();
+ this.cache = cacheManager.createCache(name, config);
+
+ logger.info("Arcus k/v local cache is enabled : %s", cache.toString());
}
public T get(String key) {
@@ -78,10 +66,10 @@ public T get(String key) {
}
try {
- Element element = cache.get(key);
- if (null != element) {
+ Object value = cache.get(key);
+ if (null != value) {
logger.debug("ArcusFrontCache: local cache hit for %s", key);
- @SuppressWarnings("unchecked") T ret = (T) element.getObjectValue();
+ @SuppressWarnings("unchecked") T ret = (T) value;
return ret;
}
} catch (Exception e) {
@@ -101,21 +89,13 @@ public T call() throws Exception {
return task;
}
- public Element getElement(String key) {
- Element element = cache.get(key);
- if (null != element) {
- logger.debug("ArcusFrontCache: local cache hit for %s", key);
- }
- return element;
- }
-
public boolean put(String k, T v) {
if (v == null) {
return false;
}
try {
- cache.put(new Element(k, v));
+ cache.put(k, v);
return true;
} catch (Exception e) {
logger.info("failed to put to the local cache : %s", e.getMessage());