atg.service.cache
Interface CacheAdapter

All Known Implementing Classes:
InventoryCacheAdapter, PriceCacheAdapter

public interface CacheAdapter

Used in conjunction with the Cache class.

Clients should implement this interface and call setCacheAdapter on the Cache with an instance of their class.


Field Summary
static java.lang.String CLASS_VERSION
           
 
Method Summary
 java.lang.Object getCacheElement(java.lang.Object key)
          Gets the element to be stored in the cache with the given key.
 java.lang.Object[] getCacheElements(java.lang.Object[] keys)
          Returns the array of elements corresponding to the given array of keys.
 int getCacheElementSize(java.lang.Object element, java.lang.Object key)
          Returns the approximate size in bytes of the given cache element.
 int getCacheKeySize(java.lang.Object key)
          Returns the approximate size in bytes of the given cache key.
 void removeCacheElement(java.lang.Object element, java.lang.Object key)
          This method is called by the synchronized method Cache.remove to allow the adapter to do any related clean up, if necessary, when an element is removed from the cache.
 

Field Detail

CLASS_VERSION

static final java.lang.String CLASS_VERSION
See Also:
Constant Field Values
Method Detail

getCacheElement

java.lang.Object getCacheElement(java.lang.Object key)
                                 throws java.lang.Exception
Gets the element to be stored in the cache with the given key. Returns null if no element can be found for the given key.

Throws:
java.lang.Exception - if some form of exception occurs while attempting to retrieve the element (e.g., SQLException). Since the type of exceptions possible depend upon the implementation of the adapter, the interface allows for generic exceptions.

getCacheElements

java.lang.Object[] getCacheElements(java.lang.Object[] keys)
                                    throws java.lang.Exception
Returns the array of elements corresponding to the given array of keys. This method is provided as part of the interface to allow for more efficient retrieval of multiple elements than getting them one at a time. Implementations of this method are required to return an array of elements ordered the same as the corresponding keys in the input array. If an element cannot be found for any given key, the value returned for that array element should be null.

Throws:
java.lang.Exception - if some form of exception occurs while attempting to retrieve the elements (e.g., SQLException). Since the type of exceptions possible depend upon the implementation of the adapter, the interface allows for generic exceptions.

getCacheKeySize

int getCacheKeySize(java.lang.Object key)
Returns the approximate size in bytes of the given cache key. The implementation may choose to simply return zero if the size cannot be determined, but assuming both size methods return zero, the maximumEntrySize and maximumCacheSize properties of the cache using this adapter will in effect be ignored and only the maximumCacheEntries property will limit the cache size.


getCacheElementSize

int getCacheElementSize(java.lang.Object element,
                        java.lang.Object key)
Returns the approximate size in bytes of the given cache element. (The key is passed in as well in case the implementation needs it for any reason.) The implementation my choose to simply return zero if the size cannot be determined, but assuming both size methods return zero, the maximumEntrySize and maximumCacheSize properties of the cache using this adapter will in effect be ignored and only the maximumCacheEntries property will limit the cache size.


removeCacheElement

void removeCacheElement(java.lang.Object element,
                        java.lang.Object key)
This method is called by the synchronized method Cache.remove to allow the adapter to do any related clean up, if necessary, when an element is removed from the cache. Most adapters will simply implement this as an empty method.