@Override
                public void completed(final CAS cas) {
                    try {
                        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, callback);
                        } else {
                            final T storageObject = serializer.serialize(new HttpCacheStorageEntry(key, updatedEntry));
                            complexCancellable.setDependency(updateCAS(storageKey, cas, storageObject, new FutureCallback<Boolean>() {

                                @Override
                                public void completed(final Boolean result) {
                                    if (result.booleanValue()) {
                                        callback.completed(result);
                                    } else {
                                        if (!complexCancellable.isCancelled()) {
                                            final int numRetries = count.incrementAndGet();
                                            if (numRetries >= maxUpdateRetries) {
                                                callback.failed(new HttpCacheUpdateException("Cache update failed after " + numRetries + " retries"));
                                            } else {
                                                attemptUpdateEntry(key, casOperation, complexCancellable, count, callback);
                                            }
                                        }
                                    }
                                }

                                @Override
                                public void failed(final Exception ex) {
                                    callback.failed(ex);
                                }

                                @Override
                                public void cancelled() {
                                    callback.cancelled();
                                }

                            }));
                        }
                    } catch (final Exception ex) {
                        callback.failed(ex);
                    }
                }
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/AbstractSerializingAsyncCacheStorage.java