Expresso 5-5-0

com.jcorporate.expresso.core.cache
Interface Cache

All Known Implementing Classes:
OrderedCache, UnOrderedCache

public interface Cache

A cache is a list of Cacheable objects that can be stored in memory, cleared, added to and removed from. It also stores information about how many times it has been used. This interface defines how a generic cache object should behave, but the specifics are up to the implementor.

Implementation Note: The implementation of ordered or unordered caches should be such that getItems() or getItem() will NEVER return an expired cache item. Implementations should check isExpired() before adding the cache item to the return list.


Method Summary
 void addItem(CacheEntry newItem)
          Add a new item to the cache.
 void clear()
          Clear all items from the cache
 CacheEntry getCacheEntry(String itemKey)
          Retrieve the low-level CacheEntry for the cache.
 Cacheable getItem(String itemKey)
          Get the item indicated by the given key from the cache.
 int getItemCount()
          Retrieve Cache Item Count
 Vector getItems()
          Get all the items in the cache
 String getName()
          Get the name of the cache
 long getUsedCount()
          Get how many times this cache has been used
 boolean isOrdered()
          Retrieve whether the cache instance is an ordered cache [list based] or unordered cache.
 void removeItem(Cacheable itemKey)
          Removes the specified item from the cache.
 void setItems(List newItems)
          Eventually the new way to set items
 void setItems(Vector newItems)
          Set the items in the cache
 void setMaxSize(int newMax)
          Sets the maximum size of the cache
 void setName(String newName)
          Sets the name of the cache
 

Method Detail

addItem

public void addItem(CacheEntry newItem)
Add a new item to the cache.

Parameters:
newItem - the new item to add to the cache

clear

public void clear()
Clear all items from the cache


getCacheEntry

public CacheEntry getCacheEntry(String itemKey)
Retrieve the low-level CacheEntry for the cache. This is particularly useful for debugging or management.

Parameters:
itemKey - the key for the entry
Returns:
a CacheEntry object or null if it doesn't exist

getItem

public Cacheable getItem(String itemKey)
Get the item indicated by the given key from the cache. All Cacheable items define a getKey() method that defines how the item is differentated from other items in the cache

Parameters:
itemKey - the key of the item to retrieve
Returns:
the Object stored in the cache.

isOrdered

public boolean isOrdered()
Retrieve whether the cache instance is an ordered cache [list based] or unordered cache. [map based]

Returns:
true if the cache is an ordered cache.

getItemCount

public int getItemCount()
Retrieve Cache Item Count

Returns:
The number of items in the cache

getItems

public Vector getItems()
Get all the items in the cache

Returns:
java.util.Vector - The items in the cache

getName

public String getName()
Get the name of the cache

Returns:
java.lang.String the name of the cache.

getUsedCount

public long getUsedCount()
Get how many times this cache has been used

Returns:
long

removeItem

public void removeItem(Cacheable itemKey)
Removes the specified item from the cache.

Parameters:
itemKey - The item in the cache to remove

setItems

public void setItems(Vector newItems)
              throws CacheException
Set the items in the cache

Parameters:
newItems - The vector of new items
Throws:
CacheException - If there's an error setting the new items in the cache

setItems

public void setItems(List newItems)
              throws CacheException
Eventually the new way to set items

Parameters:
newItems - the new items to add
Throws:
CacheException - upon error

setMaxSize

public void setMaxSize(int newMax)
Sets the maximum size of the cache

Parameters:
newMax - The new maximum size of the cache.

setName

public void setName(String newName)
Sets the name of the cache

Parameters:
newName - java.lang.String The new name of the cache.

Expresso 5-5-0

Please see www.jcorporate.com for information about new Expresso releases.