Expresso 5-5-0

com.jcorporate.expresso.core.cache
Interface CacheSystem

All Known Implementing Classes:
DefaultCacheManager

public interface CacheSystem

This is an interface for an underlying cache system. It allows clients of the itnerface to add items, retrieve items, and clear caches.

The CacheSystem is not data context aware. Classes that implement this interface are expected to be one instance per context. The Component System provides differentiation between caches.

Since:
Expresso 5.1
Author:
Michael Rimov

Method Summary
 void addItem(String cacheName, Cacheable newItem)
          Adds a Cacheable item into the cache
 void addItem(String cacheName, Cacheable newItem, long expiry)
          Adds an item to the cache named by parameter cacheName
 void addListener(String listener, String listenTo)
          Specify a relationship between caches.
 void adjustForMemory()
          Instructs the cache system to adjust it's usage profile based upon current memory information that the expresso system is telling us.
 void clear()
          Removes all cache items for a particular data context
 void clear(String cacheName)
          Clear's the named cache.
 void clearNoNotify()
          Clears all caches in this db context but doesn't notify any listeners
 void clearNoNotify(String cacheName)
          Clear the named cache, but don't send the remote system notifications.
 Cache createCache(String cacheName, boolean ordered)
          Creates a cache as specified by the parameters listed.
 Cache createCache(String cacheName, boolean ordered, int maxSize)
          Creates a cache defined by whether the cache is to be ordered, it's name and it's maximum size.
 void displayStatus()
          Displays the cache status.
 boolean existsCache(String cacheName)
          Checks to see if the cache already exists.
 Set getAllCacheNames()
          Return an iterator over a list of Strings that contain all the names of the caches stored in the system [For dbContext default]
 Cache getCache(String cacheName)
          Retrieve a given cache by name.
 Cacheable getItem(String cacheName, String valueKey)
          Get a particular item in the cache
 int getItemCount(String cacheName)
          Return a count of the number of items in a cache.
 List getItems(String cacheName)
          Return all of the items in a cache.
 void removeItem(String cacheName, Cacheable itemToRemove)
          Removes an item from the cache
 void removeItemNoNotify(String cacheName, Cacheable itemToRemove)
          Removes an item out of the cache without notifying the cache listeners
 void setItems(String cacheName, List itemList)
          Sets a cache to have the particular items specified in itemList.
 void setItems(String cacheName, List itemList, long expiration)
          Sets a cache to have the particular items specified in itemList.
 

Method Detail

adjustForMemory

public void adjustForMemory()
Instructs the cache system to adjust it's usage profile based upon current memory information that the expresso system is telling us.


getAllCacheNames

public Set getAllCacheNames()
Return an iterator over a list of Strings that contain all the names of the caches stored in the system [For dbContext default]

Returns:
java.util.Iterator

getItem

public Cacheable getItem(String cacheName,
                         String valueKey)
Get a particular item in the cache

Parameters:
cacheName - The name of the cache
valueKey - The particular item within the cache to get
Returns:
a Cacheable object or null if it doesn't exist in the cache

getCache

public Cache getCache(String cacheName)
Retrieve a given cache by name.

Parameters:
cacheName - the name of the cache to retrieve.
Returns:
a Cache instance or null if the Cache does not exist.
See Also:
Cache

getItemCount

public int getItemCount(String cacheName)
Return a count of the number of items in a cache. Return 0 if there is no such item

Parameters:
cacheName - The name of the cache
Returns:
an item count or zero if the cache doesn't exist or is empty;

setItems

public void setItems(String cacheName,
                     List itemList)
              throws CacheException
Sets a cache to have the particular items specified in itemList.

Parameters:
cacheName - The name of the cache
itemList - The items to set into the cache
Throws:
CacheException - if there's an error setting the items.

setItems

public void setItems(String cacheName,
                     List itemList,
                     long expiration)
              throws CacheException
Sets a cache to have the particular items specified in itemList.

Parameters:
cacheName - The name of the cache
itemList - The items to set into the cache
expiration - the expiration time in milliseconds for the items.
Throws:
CacheException - if there's an error setting the items.

getItems

public List getItems(String cacheName)
Return all of the items in a cache. If the cache was created as an ordered cache, the items will be in the order they were added. If not, they will be in no particular order. If there is no such cache or no items, null will be returned.

Parameters:
cacheName - The name of the cache to retrieve
Returns:
java.util.List of Cacheable items

addItem

public void addItem(String cacheName,
                    Cacheable newItem)
             throws CacheException
Adds a Cacheable item into the cache

Parameters:
cacheName - The name of the cache.
newItem - The new item to add to the cache
Throws:
CacheException - upon error inserting into the system

addItem

public void addItem(String cacheName,
                    Cacheable newItem,
                    long expiry)
             throws CacheException
Adds an item to the cache named by parameter cacheName

Parameters:
cacheName - The name of the cache to store the object in
newItem - The new item to add to the cache
expiry - The time in miliseconds that this cache item will expire
Throws:
CacheException - if there's an error inserting the item into the cache

addListener

public void addListener(String listener,
                        String listenTo)
Specify a relationship between caches. Whenever an add clear or remove event is sent to the specified cache, the listener is cleared as well. Adding a listener implies the relationship between the caches for the current db context.

Parameters:
listener - The classname of the listener
listenTo - The name of the cache to listen to.

clear

public void clear(String cacheName)
           throws CacheException
Clear's the named cache.

Parameters:
cacheName - The name of the cache to clear
Throws:
CacheException - if there's an error clearing the cache.

clear

public void clear()
           throws CacheException
Removes all cache items for a particular data context

Throws:
CacheException - CacheException if there's an error clearing the cache

clearNoNotify

public void clearNoNotify()
Clears all caches in this db context but doesn't notify any listeners


clearNoNotify

public void clearNoNotify(String cacheName)
Clear the named cache, but don't send the remote system notifications. This method actually removes the cache from the list of available caches

Parameters:
cacheName - The name of the cache

createCache

public Cache createCache(String cacheName,
                         boolean ordered)
                  throws CacheException
Creates a cache as specified by the parameters listed. Creation date: (9/7/00 2:18:09 PM)

Parameters:
cacheName - java.lang.String the name of the cache
ordered - boolean true if you want an ordered cache such as for ValidValues
Returns:
the newly instantiated Cache
Throws:
CacheException

createCache

public Cache createCache(String cacheName,
                         boolean ordered,
                         int maxSize)
                  throws CacheException
Creates a cache defined by whether the cache is to be ordered, it's name and it's maximum size. Creation date: (9/7/00 2:18:09 PM)

Parameters:
cacheName - java.lang.String The name of the cache
ordered - boolean True if you wish for an ordered cache.
maxSize - The maximum size of the cache
Returns:
the newly instantiated cache
Throws:
CacheException

existsCache

public boolean existsCache(String cacheName)
Checks to see if the cache already exists. One big note about this is that unless you already have a ReadLock, the cache may or may not exist once you go to put your data in the cache. Buyer beware.

Parameters:
cacheName - The name of the cache
Returns:
true if the named cache already exists in this data context

removeItem

public void removeItem(String cacheName,
                       Cacheable itemToRemove)
                throws CacheException
Removes an item from the cache

Parameters:
cacheName - The name of the cache
itemToRemove - the key of the item to remove
Throws:
CacheException

removeItemNoNotify

public void removeItemNoNotify(String cacheName,
                               Cacheable itemToRemove)
                        throws CacheException
Removes an item out of the cache without notifying the cache listeners

Parameters:
cacheName - The cache name
itemToRemove - the key in the cache that has been modified
Throws:
CacheException - Upon error removing the item from the cache

displayStatus

public void displayStatus()
Displays the cache status. Currently this is only really used for debugging purposes. Creation date: (9/7/00 2:44:05 PM)


Expresso 5-5-0

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