You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2023/09/29 13:23:43 UTC

[httpcomponents-client] branch 5.2.x updated: More consistent handling of OperationTimeoutException in MemcachedHttpCacheStorage

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch 5.2.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/5.2.x by this push:
     new 6105852b6 More consistent handling of OperationTimeoutException in MemcachedHttpCacheStorage
6105852b6 is described below

commit 6105852b6b1320250be71f8e388dff9159f44889
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Fri Sep 29 15:05:16 2023 +0200

    More consistent handling of OperationTimeoutException in MemcachedHttpCacheStorage
---
 .../cache/memcached/MemcachedHttpCacheStorage.java | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

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 a8ff8ff5a..fe66d2cc0 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
@@ -208,8 +208,12 @@ public class MemcachedHttpCacheStorage extends AbstractBinaryCacheStorage<CASVal
     @Override
     protected boolean updateCAS(
             final String storageKey, final CASValue<Object> casValue, final byte[] storageObject) throws ResourceIOException {
-        final CASResponse casResult = client.cas(storageKey, casValue.getCas(), storageObject);
-        return casResult == CASResponse.OK;
+        try {
+            final CASResponse casResult = client.cas(storageKey, casValue.getCas(), storageObject);
+            return casResult == CASResponse.OK;
+        } catch (final OperationTimeoutException ex) {
+            throw new MemcachedOperationTimeoutException(ex);
+        }
     }
 
     @Override
@@ -219,12 +223,16 @@ public class MemcachedHttpCacheStorage extends AbstractBinaryCacheStorage<CASVal
 
     @Override
     protected Map<String, byte[]> bulkRestore(final Collection<String> storageKeys) throws ResourceIOException {
-        final Map<String, ?> storageObjectMap = client.getBulk(storageKeys);
-        final Map<String, byte[]> resultMap = new HashMap<>(storageObjectMap.size());
-        for (final Map.Entry<String, ?> resultEntry: storageObjectMap.entrySet()) {
-            resultMap.put(resultEntry.getKey(), castAsByteArray(resultEntry.getValue()));
+        try {
+            final Map<String, ?> storageObjectMap = client.getBulk(storageKeys);
+            final Map<String, byte[]> resultMap = new HashMap<>(storageObjectMap.size());
+            for (final Map.Entry<String, ?> resultEntry: storageObjectMap.entrySet()) {
+                resultMap.put(resultEntry.getKey(), castAsByteArray(resultEntry.getValue()));
+            }
+            return resultMap;
+        } catch (final OperationTimeoutException ex) {
+            throw new MemcachedOperationTimeoutException(ex);
         }
-        return resultMap;
     }
 
 }