michael@0: /* michael@0: * Copyright (C) 2013 Square, Inc. michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: package com.squareup.picasso; michael@0: michael@0: import android.graphics.Bitmap; michael@0: michael@0: /** michael@0: * A memory cache for storing the most recently used images. michael@0: *

michael@0: * Note: The {@link Cache} is accessed by multiple threads. You must ensure michael@0: * your {@link Cache} implementation is thread safe when {@link Cache#get(String)} or {@link michael@0: * Cache#set(String, android.graphics.Bitmap)} is called. michael@0: */ michael@0: public interface Cache { michael@0: /** Retrieve an image for the specified {@code key} or {@code null}. */ michael@0: Bitmap get(String key); michael@0: michael@0: /** Store an image in the cache for the specified {@code key}. */ michael@0: void set(String key, Bitmap bitmap); michael@0: michael@0: /** Returns the current size of the cache in bytes. */ michael@0: int size(); michael@0: michael@0: /** Returns the maximum size in bytes that the cache can hold. */ michael@0: int maxSize(); michael@0: michael@0: /** Clears the cache. */ michael@0: void clear(); michael@0: michael@0: /** A cache which does not store any values. */ michael@0: Cache NONE = new Cache() { michael@0: @Override public Bitmap get(String key) { michael@0: return null; michael@0: } michael@0: michael@0: @Override public void set(String key, Bitmap bitmap) { michael@0: // Ignore. michael@0: } michael@0: michael@0: @Override public int size() { michael@0: return 0; michael@0: } michael@0: michael@0: @Override public int maxSize() { michael@0: return 0; michael@0: } michael@0: michael@0: @Override public void clear() { michael@0: } michael@0: }; michael@0: }