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 */ 16package com.squareup.okhttp; 17 18import java.io.IOException; 19import java.net.CacheRequest; 20 21/** 22 * An extended response cache API. Unlike {@link java.net.ResponseCache}, this 23 * interface supports conditional caching and statistics. 24 */ 25public interface OkResponseCache { 26 Response get(Request request) throws IOException; 27 28 CacheRequest put(Response response) throws IOException; 29 30 /** 31 * Remove any cache entries for the supplied {@code uri}. Returns true if the 32 * supplied {@code requestMethod} potentially invalidates an entry in the 33 * cache. 34 */ 35 // TODO: this shouldn't return a boolean. 36 boolean maybeRemove(Request request) throws IOException; 37 38 /** 39 * Handles a conditional request hit by updating the stored cache response 40 * with the headers from {@code network}. The cached response body is not 41 * updated. If the stored response has changed since {@code cached} was 42 * returned, this does nothing. 43 */ 44 void update(Response cached, Response network) throws IOException; 45 46 /** Track an conditional GET that was satisfied by this cache. */ 47 void trackConditionalCacheHit(); 48 49 /** Track an HTTP response being satisfied by {@code source}. */ 50 void trackResponse(ResponseSource source); 51} 52