edu.toronto.cs.util.caching
Interface Cache

All Known Implementing Classes:
AbstractMapCache, NaiveMapCache, NullCache, UnboundedMapCache

public interface Cache

Cache interface.


Method Summary
 void clear()
          Clears the cache.
 boolean containsKey(java.lang.Object key)
          Checks whether the cache contains a value associated with the key.
 boolean containsValue(java.lang.Object value)
          Checks whether the cache contains the specified value.
 java.util.Set entrySet()
          Returns a Set representation of the cache mapping.
 java.lang.Object get(java.lang.Object key)
          Retrieves a value with the specified key from the cache.
 boolean isEmpty()
          Determines if the cache is empty.
 java.util.Set keySet()
          Gets the set of all the keys registered in the cahce.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Stores a value and assotiates a key with it.
 java.lang.Object remove(java.lang.Object key)
          Removes a value with the specified key from the cache.
 void resize(int size)
          Sets the maximum cache size.
 int size()
          Returns the number of elements in cache.
 java.util.Collection values()
          Gets a collection view of the values contained in this map.
 

Method Detail

clear

void clear()
Clears the cache.


containsKey

boolean containsKey(java.lang.Object key)
Checks whether the cache contains a value associated with the key.

Parameters:
key - -- the key to look for.
Returns:
-- true if the key is in the cache; false otherwise.

containsValue

boolean containsValue(java.lang.Object value)
Checks whether the cache contains the specified value.

Parameters:
value - -- the value to look for.
Returns:
-- true if the value is in the cache; false otherwise.

put

java.lang.Object put(java.lang.Object key,
                     java.lang.Object value)
Stores a value and assotiates a key with it. If the key already has a value associated with it, the old value is replaced by the supplied new value and returned.

Parameters:
key - -- the key associated with the value.
value - -- value to store.
Returns:
-- the value that has been previously associated with the key or null if none exists.

get

java.lang.Object get(java.lang.Object key)
Retrieves a value with the specified key from the cache.

Parameters:
key - -- the key associated with the value.
Returns:
-- the value associated with the key or null if not found.

remove

java.lang.Object remove(java.lang.Object key)
Removes a value with the specified key from the cache. If there's no mapping for the specified key, does nothing.

Parameters:
key - -- the key associated with the value.
Returns:
-- the value being removed or null if no such key exists.

size

int size()
Returns the number of elements in cache.

Returns:
-- the number of elements in cashe.

isEmpty

boolean isEmpty()
Determines if the cache is empty.

Returns:
-- true if th cache is empty and false otherwise.

values

java.util.Collection values()
Gets a collection view of the values contained in this map.

Returns:
-- collection view of the values contained in this map.

keySet

java.util.Set keySet()
Gets the set of all the keys registered in the cahce.

Returns:
-- the Set of all keys in cache.

entrySet

java.util.Set entrySet()
Returns a Set representation of the cache mapping.

Returns:
-- a Set representing the cache.

resize

void resize(int size)
Sets the maximum cache size. If the cache is currently bigger than specified size, the excess elements get purged.

Parameters:
size - -- the maximum cache size.