@Override
    public final void updateEntry(
            final String key,
            final HttpCacheCASOperation casOperation) throws HttpCacheUpdateException, ResourceIOException {
        int numRetries = 0;
        final String storageKey = digestToStorageKey(key);
        for (;;) {
            final CAS cas = getForUpdateCAS(storageKey);
            HttpCacheStorageEntry storageEntry = cas != null ? serializer.deserialize(getStorageObject(cas)) : null;
            if (storageEntry != null && !key.equals(storageEntry.getKey())) {
                storageEntry = null;
            }
            final HttpCacheEntry existingEntry = storageEntry != null ? storageEntry.getContent() : null;
            final HttpCacheEntry updatedEntry = casOperation.execute(existingEntry);

            if (existingEntry == null) {
                putEntry(key, updatedEntry);
                return;

            }
            final T storageObject = serializer.serialize(new HttpCacheStorageEntry(key, updatedEntry));
            if (!updateCAS(storageKey, cas, storageObject)) {
                numRetries++;
                if (numRetries >= maxUpdateRetries) {
                    throw new HttpCacheUpdateException("Cache update failed after " + numRetries + " retries");
                }
            } else {
                return;
            }
        }
    }
Abstract cache backend for serialized objects capable of CAS (compare-and-swap) updates.

@since 5.0
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingCacheStorage.java