Expresso 5-6

com.jcorporate.expresso.core.cache
Class UnOrderedCache

java.lang.Object
  extended bycom.jcorporate.expresso.core.cache.UnOrderedCache
All Implemented Interfaces:
Cache

public class UnOrderedCache
extends Object
implements Cache

Unordered cache is a hash map backed class. As such, access to individual items is relatively quick. However getting all the items in cache is a very slow process, and the order of the items is not guaranteed.

If the size of the unordered cache is specified, then the cache automatically uses the least recently used (LRU) algorithm to determine which items should be removed from the cache.

Unless you need to specifically store arrays of objects then this will be the cache to use for most of your needs. Creation date: (9/7/00 11:47:14 AM)


Constructor Summary
UnOrderedCache()
          UnOrderedCache constructor comment.
 
Method Summary
 void addItem(CacheEntry newItem)
          Adds an item to this cache
 void clear()
          Clear the cache by creating a new map
 CacheEntry getCacheEntry(String itemKey)
          Retrieve the cache entry specified by the item key
 Cacheable getItem(String itemKey)
          Get an item as defined by the key.
 int getItemCount()
          Get the number of items in the cache
 Vector getItems()
          Return all the items in a Vector This is a REALLY messy function for unordered caches.
 String getName()
          Returns the name of this cache
 long getUsedCount()
          Return the number of times this cache has been accessed
 boolean isOrdered()
          Retrieve whether the cache instance is an ordered cache [list based] or unordered cache.
 void removeItem(Cacheable oldItem)
          Removes an item as keyed by the paramter
 void setItems(List newItems)
          Eventually the new way to set items
 void setItems(Vector newItems)
          Goes through all the new items and adds them to the list.
 void setMaxSize(int newMaxSize)
          Sets the maximum size for the cache.
 void setName(String newName)
          Sets the name of the cache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnOrderedCache

public UnOrderedCache()
UnOrderedCache constructor comment.

Method Detail

addItem

public void addItem(CacheEntry newItem)
Adds an item to this cache

Specified by:
addItem in interface Cache
Parameters:
newItem - The new item to cache

clear

public void clear()
Clear the cache by creating a new map

Specified by:
clear in interface Cache

getCacheEntry

public CacheEntry getCacheEntry(String itemKey)
Retrieve the cache entry specified by the item key

Specified by:
getCacheEntry in interface Cache
Parameters:
itemKey - the key for the cache entry
Returns:
the resulting cache entry or null if it no longer exists.

getItem

public Cacheable getItem(String itemKey)
Get an item as defined by the key.

Specified by:
getItem in interface Cache
Parameters:
itemKey - The item's key
Returns:
Cacheable object or null if it doesn't exist in the cache

getItemCount

public int getItemCount()
Get the number of items in the cache

Specified by:
getItemCount in interface Cache
Returns:
the number of items in this cache

getItems

public Vector getItems()
Return all the items in a Vector This is a REALLY messy function for unordered caches. Use very INFREQUENTLY

Specified by:
getItems in interface Cache
Returns:
java.util.Vector of all the items.

getName

public String getName()
Returns the name of this cache

Specified by:
getName in interface Cache
Returns:
java.lang.String the name of the cache

getUsedCount

public long getUsedCount()
Return the number of times this cache has been accessed

Specified by:
getUsedCount in interface Cache
Returns:
the number of times accessed as integer

isOrdered

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

Specified by:
isOrdered in interface Cache
Returns:
true if the cache is an ordered cache.

removeItem

public void removeItem(Cacheable oldItem)
Removes an item as keyed by the paramter

Specified by:
removeItem in interface Cache
Parameters:
oldItem - The item to remove.

setItems

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

Specified by:
setItems in interface Cache
Parameters:
newItems - the new items to add
Throws:
CacheException - upon error

setItems

public void setItems(Vector newItems)
              throws CacheException
Goes through all the new items and adds them to the list.

Specified by:
setItems in interface Cache
Parameters:
newItems - A java.util.Vector of new items to add to the cache list
Throws:
CacheException - if there's an error adding the cache entry items

setMaxSize

public void setMaxSize(int newMaxSize)
Sets the maximum size for the cache. If it is greater than zero then we use an LRU Map instead of a normal hashmap to provide automatic removal of old items.

Specified by:
setMaxSize in interface Cache
Parameters:
newMaxSize - The new maximum size to use for the cache

setName

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

Specified by:
setName in interface Cache
Parameters:
newName - the new name to set for the cache.

Expresso 5-6

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