001/* 002 * Cache.java July 2006 003 * 004 * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net> 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 015 * implied. See the License for the specific language governing 016 * permissions and limitations under the License. 017 */ 018 019package org.simpleframework.xml.util; 020 021/** 022 * The <code>Cache</code> interface is used to represent a cache 023 * that will store key value pairs. The cache exposes only several 024 * methods to ensure that implementations can focus on performance 025 * concerns rather than how to manage the cached values. 026 * 027 * @author Niall Gallagher 028 */ 029public interface Cache<T> { 030 031 /** 032 * This method is used to determine if the cache is empty. This 033 * is done by checking if there are any elements in the cache. 034 * If anything has been cached this will return false. 035 * 036 * @return this returns true if the cache is empty 037 */ 038 boolean isEmpty(); 039 040 /** 041 * This method is used to insert a key value mapping in to the 042 * cache. The value can later be retrieved or removed from the 043 * cache if desired. If the value associated with the key is 044 * null then nothing is stored within the cache. 045 * 046 * @param key this is the key to cache the provided value to 047 * @param value this is the value that is to be cached 048 */ 049 void cache(Object key, T value); 050 051 /** 052 * This is used to exclusively take the value mapped to the 053 * specified key from the cache. Invoking this is effectively 054 * removing the value from the cache. 055 * 056 * @param key this is the key to acquire the cache value with 057 * 058 * @return this returns the value mapped to the specified key 059 */ 060 T take(Object key); 061 062 /** 063 * This method is used to get the value from the cache that is 064 * mapped to the specified key. If there is no value mapped to 065 * the specified key then this method will return a null. 066 * 067 * @param key this is the key to acquire the cache value with 068 * 069 * @return this returns the value mapped to the specified key 070 */ 071 T fetch(Object key); 072 073 /** 074 * This is used to determine whether the specified key exists 075 * with in the cache. Typically this can be done using the 076 * fetch method, which will acquire the object. 077 * 078 * @param key this is the key to check within this segment 079 * 080 * @return true if the specified key is within the cache 081 */ 082 boolean contains(Object key); 083}