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.List;
31
32 import org.apache.hc.client5.http.cache.HttpCacheEntry;
33 import org.apache.hc.core5.http.HttpHost;
34 import org.apache.hc.core5.http.HttpRequest;
35 import org.apache.hc.core5.http.HttpResponse;
36 import org.apache.hc.core5.util.ByteArrayBuffer;
37
38 interface HttpCache {
39
40 /**
41 * Returns a result with either a fully matching {@link HttpCacheEntry}
42 * a partial match with a list of known variants or null if no match could be found.
43 */
44 CacheMatch match(HttpHost host, HttpRequest request);
45
46 /**
47 * Retrieves variant {@link HttpCacheEntry}s for the given hit.
48 */
49 List<CacheHit> getVariants(CacheHit hit);
50
51 /**
52 * Stores {@link HttpRequest} / {@link HttpResponse} exchange details in the cache.
53 */
54 CacheHit store(
55 HttpHost host,
56 HttpRequest request,
57 HttpResponse originResponse,
58 ByteArrayBuffer content,
59 Instant requestSent,
60 Instant responseReceived);
61
62 /**
63 * Updates {@link HttpCacheEntry} using details from a 304 {@link HttpResponse} and
64 * updates the root entry if the given cache entry represents a variant.
65 */
66 CacheHit update(
67 CacheHit stale,
68 HttpHost host,
69 HttpRequest request,
70 HttpResponse originResponse,
71 Instant requestSent,
72 Instant responseReceived);
73
74 /**
75 * Stores {@link HttpRequest} / {@link HttpResponse} exchange details in the cache
76 * from the negotiated {@link HttpCacheEntry}.
77 */
78 CacheHit storeFromNegotiated(
79 CacheHit negotiated,
80 HttpHost host,
81 HttpRequest request,
82 HttpResponse originResponse,
83 Instant requestSent,
84 Instant responseReceived);
85
86 /**
87 * Evicts {@link HttpCacheEntry}s invalidated by the given message exchange.
88 */
89 void evictInvalidatedEntries(HttpHost host, HttpRequest request, HttpResponse response);
90
91 }