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