1 /* 2 * Copyright (C) 2013 Square, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.squareup.okhttp.internal; 17 18 import com.squareup.okhttp.Request; 19 import com.squareup.okhttp.Response; 20 import com.squareup.okhttp.internal.http.CacheRequest; 21 import com.squareup.okhttp.internal.http.CacheStrategy; 22 import java.io.IOException; 23 24 /** 25 * OkHttp's internal cache interface. Applications shouldn't implement this: 26 * instead use {@link com.squareup.okhttp.Cache}. 27 */ 28 public interface InternalCache { get(Request request)29 Response get(Request request) throws IOException; 30 put(Response response)31 CacheRequest put(Response response) throws IOException; 32 33 /** 34 * Remove any cache entries for the supplied {@code request}. This is invoked 35 * when the client invalidates the cache, such as when making POST requests. 36 */ remove(Request request)37 void remove(Request request) throws IOException; 38 39 /** 40 * Handles a conditional request hit by updating the stored cache response 41 * with the headers from {@code network}. The cached response body is not 42 * updated. If the stored response has changed since {@code cached} was 43 * returned, this does nothing. 44 */ update(Response cached, Response network)45 void update(Response cached, Response network) throws IOException; 46 47 /** Track an conditional GET that was satisfied by this cache. */ trackConditionalCacheHit()48 void trackConditionalCacheHit(); 49 50 /** Track an HTTP response being satisfied with {@code cacheStrategy}. */ trackResponse(CacheStrategy cacheStrategy)51 void trackResponse(CacheStrategy cacheStrategy); 52 } 53