diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingCacheStorage.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingCacheStorage.java index 108f9a6210..b0a24d3280 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingCacheStorage.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingCacheStorage.java @@ -26,6 +26,7 @@ */ package org.apache.hc.client5.http.impl.cache; +import java.time.Instant; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -60,6 +61,13 @@ public AbstractSerializingCacheStorage(final int maxUpdateRetries, final HttpCac protected abstract void store(String storageKey, T storageObject) throws ResourceIOException; + /** + * @since 5.6 + */ + protected void store(final String storageKey, final Instant expectedExpiry, final T storageObject) throws ResourceIOException { + store(storageKey, storageObject); + } + protected abstract T restore(String storageKey) throws ResourceIOException; protected abstract CAS getForUpdateCAS(String storageKey) throws ResourceIOException; @@ -76,7 +84,8 @@ public AbstractSerializingCacheStorage(final int maxUpdateRetries, final HttpCac public final void putEntry(final String key, final HttpCacheEntry entry) throws ResourceIOException { final String storageKey = digestToStorageKey(key); final T storageObject = serializer.serialize(new HttpCacheStorageEntry(key, entry)); - store(storageKey, storageObject); + final Instant expires = entry.getExpires(); + store(storageKey, expires, storageObject); } @Override diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedHttpCacheStorage.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedHttpCacheStorage.java index 84ec2aa37b..3b62d22829 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedHttpCacheStorage.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedHttpCacheStorage.java @@ -28,11 +28,19 @@ import java.io.IOException; import java.net.InetSocketAddress; +import java.time.Duration; +import java.time.Instant; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CancellationException; +import java.util.function.BiFunction; +import net.spy.memcached.CASResponse; +import net.spy.memcached.CASValue; +import net.spy.memcached.MemcachedClient; +import net.spy.memcached.MemcachedClientIF; +import net.spy.memcached.OperationTimeoutException; import org.apache.hc.client5.http.cache.HttpCacheEntrySerializer; import org.apache.hc.client5.http.cache.ResourceIOException; import org.apache.hc.client5.http.impl.cache.AbstractBinaryCacheStorage; @@ -40,12 +48,6 @@ import org.apache.hc.client5.http.impl.cache.HttpByteArrayCacheEntrySerializer; import org.apache.hc.core5.util.Args; -import net.spy.memcached.CASResponse; -import net.spy.memcached.CASValue; -import net.spy.memcached.MemcachedClient; -import net.spy.memcached.MemcachedClientIF; -import net.spy.memcached.OperationTimeoutException; - /** *
* This class is a storage backend that uses an external memcached
@@ -88,6 +90,7 @@ public class MemcachedHttpCacheStorage extends AbstractBinaryCacheStorage