org.apache.avalon.excalibur.cache.store
Class FlipSpacesStore

java.lang.Object
  |
  +--org.apache.avalon.excalibur.cache.store.AbstractCacheStore
        |
        +--org.apache.avalon.excalibur.cache.store.FlipSpacesStore
All Implemented Interfaces:
CacheStore

public class FlipSpacesStore
extends AbstractCacheStore

Author:
Larry McCay

Constructor Summary
FlipSpacesStore(int capacity)
          Sets up the data spaces and sets the capacity of the cache
 
Method Summary
 int capacity()
          Gets the capacity for the cache.
 boolean containsKey(java.lang.Object key)
          Checks if a given key exists within either of the spaces - old and new Caches.
 java.lang.Object get(java.lang.Object key)
          Gets the cached object associated with the given name.
 java.lang.Object[] keys()
          Gets array of keys from both caches or spaces.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Puts a given name value pair into the newCache.
 java.lang.Object remove(java.lang.Object key)
          Removes the Object associated with the given name from the both spaces of this cache store.
 int size()
          Gets the current size of the newCache.
 
Methods inherited from class org.apache.avalon.excalibur.cache.store.AbstractCacheStore
isFull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FlipSpacesStore

public FlipSpacesStore(int capacity)
Sets up the data spaces and sets the capacity of the cache
Parameters:
capacity - - the size at which the cache is deemed full
Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Puts a given name value pair into the newCache. By invoking a get for the Object associated with the name before doing the actual put - we insure that the name value pair lives in the newCache data space. After executing the put - we determine if the cache is full - if so swap the data spaces - effectively clearing the newCache.
Parameters:
key - - name or key of the Object to be cached
value - - the actual cached Object
Returns:
the Object previously associated with the given name or key

remove

public java.lang.Object remove(java.lang.Object key)
Removes the Object associated with the given name from the both spaces of this cache store. By doing a get before removing the object we insure that the object if in the cache has been moved to the newCache
Parameters:
key - - name or key associated with the Object to be removed
Returns:
the removed Object

get

public java.lang.Object get(java.lang.Object key)
Gets the cached object associated with the given name. If the object does not exist within the newCache the old is checked. If the cache is determined to be full the spaces are swapped - effectively clearing the newCache. The object is then put into the newCache.
Parameters:
key - - the name or key of the requested object
Returns:
the requested Object

size

public int size()
Gets the current size of the newCache.
Returns:
newCacheSize

capacity

public int capacity()
Gets the capacity for the cache. Once the cache size has reached the capacity it is considered full.
Returns:
cache capacity

containsKey

public boolean containsKey(java.lang.Object key)
Checks if a given key exists within either of the spaces - old and new Caches.
Returns:
true if the key exists within this cache

keys

public java.lang.Object[] keys()
Gets array of keys from both caches or spaces.
Returns:
array of all the keys within this cache


Copyright © 2001 Apache Jakarta Project. All Rights Reserved.