1 /*
2 * ====================================================================
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 * ====================================================================
20 *
21 * This software consists of voluntary contributions made by many
22 * individuals on behalf of the Apache Software Foundation. For more
23 * information on the Apache Software Foundation, please see
24 * <http://www.apache.org/>.
25 *
26 */
27 package org.apache.hc.client5.http.impl.cache;
28
29 import java.time.Instant;
30 import java.util.Collection;
31
32 import org.apache.hc.client5.http.cache.HttpCacheEntry;
33 import org.apache.hc.core5.concurrent.Cancellable;
34 import org.apache.hc.core5.concurrent.FutureCallback;
35 import org.apache.hc.core5.http.HttpHost;
36 import org.apache.hc.core5.http.HttpRequest;
37 import org.apache.hc.core5.http.HttpResponse;
38 import org.apache.hc.core5.util.ByteArrayBuffer;
39
40 interface HttpAsyncCache {
41
42 /**
43 * Returns a result with either a fully matching {@link HttpCacheEntry}
44 * a partial match with a list of known variants or null if no match could be found.
45 */
46 Cancellable match(HttpHost host, HttpRequest request, FutureCallback<CacheMatch> callback);
47
48 /**
49 * Retrieves variant {@link HttpCacheEntry}s for the given hit.
50 */
51 Cancellable getVariants(
52 CacheHit hit, FutureCallback<Collection<CacheHit>> callback);
53
54 /**
55 * Stores {@link HttpRequest} / {@link HttpResponse} exchange details in the cache.
56 */
57 Cancellable store(
58 HttpHost host,
59 HttpRequest request,
60 HttpResponse originResponse,
61 ByteArrayBuffer content,
62 Instant requestSent,
63 Instant responseReceived,
64 FutureCallback<CacheHit> callback);
65
66 /**
67 * Updates {@link HttpCacheEntry} using details from a 304 {@link HttpResponse} and
68 * updates the root entry if the given cache entry represents a variant.
69 */
70 Cancellable update(
71 CacheHit stale,
72 HttpHost host,
73 HttpRequest request,
74 HttpResponse originResponse,
75 Instant requestSent,
76 Instant responseReceived,
77 FutureCallback<CacheHit> callback);
78
79 /**
80 * Stores {@link HttpRequest} / {@link HttpResponse} exchange details in the cache
81 * from the negotiated {@link HttpCacheEntry}.
82 */
83 Cancellable storeFromNegotiated(
84 CacheHit negotiated,
85 HttpHost host,
86 HttpRequest request,
87 HttpResponse originResponse,
88 Instant requestSent,
89 Instant responseReceived,
90 FutureCallback<CacheHit> callback);
91
92 /**
93 * Evicts {@link HttpCacheEntry}s invalidated by the given message exchange.
94 */
95 Cancellable evictInvalidatedEntries(
96 HttpHost host, HttpRequest request, HttpResponse response, FutureCallback<Boolean> callback);
97
98 }