org.wanghy.cache.provider.lru
Interface LruCacheManager

All Known Implementing Classes:
LruMapCacheManager

public interface LruCacheManager

A cache implementation with a fixed maximum size which removes the least recently used entry if an entry is added when full.

Version:
$Revision: 1.2 $ $Date: 2005/03/11 10:21:03 $
Author:
Alex Ruiz

Method Summary
 void clear()
          Clears the cache.
 Object get(Object key)
           Gets the value mapped to the key specified.
 int getGroupCount()
          Returns the current number of groups in the cache.
 String[] getGroupNames()
          Returns the names of the groups currently in cache.
 int getMaxSize()
          Gets the maximum size of the cache (the bound).
 int getSize()
          Returns the size of the cache.
 boolean isEmpty()
          Checks whether the cache is empty or not.
 boolean isFull()
          Returns true if the cache is full and no new mappings can be added.
 boolean isScanUntilRemovable()
          Whether the cache will scan until a removable entry is found when the map is full.
 void put(Object key, Object value, String group)
          Adds a new entry to the cache.
 void put(Object key, Object value, String group, int refreshPeriod)
          Adds a new entry to the cache.
 void remove(Object key)
          Removes an entry from the cache.
 void removeGroup(String group)
          Removes all the entries that belong to the specified group.
 

Method Detail

clear

public void clear()
Clears the cache.


get

public Object get(Object key)

Gets the value mapped to the key specified.

This operation changes the position of the key in the map to the most recently used position (first).

Parameters:
key - the key of the mapping.
Returns:
the mapped value, null if no match.

getGroupCount

public int getGroupCount()
Returns the current number of groups in the cache.

Returns:
the current number of groups in the cache.

getGroupNames

public String[] getGroupNames()
Returns the names of the groups currently in cache.

Returns:
the names of the groups currently in cache.

getMaxSize

public int getMaxSize()
Gets the maximum size of the cache (the bound).

Returns:
the maximum number of elements the cache can hold.

getSize

public int getSize()
Returns the size of the cache.

Returns:
the size of the cache.

isEmpty

public boolean isEmpty()
Checks whether the cache is empty or not.

Returns:
whether the cache is empty or not.

isFull

public boolean isFull()
Returns true if the cache is full and no new mappings can be added.

Returns:
true if the cache is full.

isScanUntilRemovable

public boolean isScanUntilRemovable()
Whether the cache will scan until a removable entry is found when the map is full.

Returns:
true if the cache scans.

put

public void put(Object key,
                Object value,
                String group)
Adds a new entry to the cache.

Parameters:
key - the key used to map the entry.
value - the object to cache.
group - the group the entry will belong to.

put

public void put(Object key,
                Object value,
                String group,
                int refreshPeriod)
Adds a new entry to the cache.

Parameters:
key - the key used to map the entry.
value - the object to cache.
group - the group the entry will belong to.
refreshPeriod - how long the entry should stay in the cache (in seconds).

remove

public void remove(Object key)
Removes an entry from the cache.

Parameters:
key - the key that identifies the entry to remove.

removeGroup

public void removeGroup(String group)
Removes all the entries that belong to the specified group.

Parameters:
group - the name of the group to remove.


Copyright © 2004-2005 Alex Ruiz. All Rights Reserved.