More consistent handling of OperationTimeoutException in MemcachedHttpCacheStorage

This commit is contained in:
Oleg Kalnichevski 2023-09-29 15:05:16 +02:00
parent 5f46cde334
commit 6105852b6b
1 changed files with 15 additions and 7 deletions

View File

@ -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;
}
}