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