Skip to content

Commit 6105852

Browse files
committed
More consistent handling of OperationTimeoutException in MemcachedHttpCacheStorage
1 parent 5f46cde commit 6105852

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedHttpCacheStorage.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,12 @@ protected byte[] getStorageObject(final CASValue<Object> casValue) throws Resour
208208
@Override
209209
protected boolean updateCAS(
210210
final String storageKey, final CASValue<Object> casValue, final byte[] storageObject) throws ResourceIOException {
211-
final CASResponse casResult = client.cas(storageKey, casValue.getCas(), storageObject);
212-
return casResult == CASResponse.OK;
211+
try {
212+
final CASResponse casResult = client.cas(storageKey, casValue.getCas(), storageObject);
213+
return casResult == CASResponse.OK;
214+
} catch (final OperationTimeoutException ex) {
215+
throw new MemcachedOperationTimeoutException(ex);
216+
}
213217
}
214218

215219
@Override
@@ -219,12 +223,16 @@ protected void delete(final String storageKey) throws ResourceIOException {
219223

220224
@Override
221225
protected Map<String, byte[]> bulkRestore(final Collection<String> storageKeys) throws ResourceIOException {
222-
final Map<String, ?> storageObjectMap = client.getBulk(storageKeys);
223-
final Map<String, byte[]> resultMap = new HashMap<>(storageObjectMap.size());
224-
for (final Map.Entry<String, ?> resultEntry: storageObjectMap.entrySet()) {
225-
resultMap.put(resultEntry.getKey(), castAsByteArray(resultEntry.getValue()));
226+
try {
227+
final Map<String, ?> storageObjectMap = client.getBulk(storageKeys);
228+
final Map<String, byte[]> resultMap = new HashMap<>(storageObjectMap.size());
229+
for (final Map.Entry<String, ?> resultEntry: storageObjectMap.entrySet()) {
230+
resultMap.put(resultEntry.getKey(), castAsByteArray(resultEntry.getValue()));
231+
}
232+
return resultMap;
233+
} catch (final OperationTimeoutException ex) {
234+
throw new MemcachedOperationTimeoutException(ex);
226235
}
227-
return resultMap;
228236
}
229237

230238
}

0 commit comments

Comments
 (0)