Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.derby.iapi.services.cache
Interface CacheManager  view CacheManager download CacheManager.java


public interface CacheManager


Method Summary
 void ageOut()
          Age as many objects as possible out of the cache.
 void clean(org.apache.derby.iapi.util.Matchable partialKey)
          Clean all objects that match the partialKey (or exact key).
 void cleanAll()
          Place all objects in their clean state by calling their clean method if they are dirty.
 boolean containsKey(java.lang.Object key)
          Determine whether a key is in the cache.
 Cacheable create(java.lang.Object key, java.lang.Object createParameter)
          Create an object in the cache.
 boolean discard(org.apache.derby.iapi.util.Matchable partialKey)
          Discard all objects that match the partialKey (or exact key).
 Cacheable find(java.lang.Object key)
          Find an object in the cache.
 Cacheable findCached(java.lang.Object key)
          Find an object in the cache.
 long[] getCacheStats()
          Return statistics about cache that may be implemented.
 long getMaximumSize()
           
 int getNumberInUse()
          Report the number of items in use (with Identity) in this cache.
 void release(Cacheable entry)
          Release a Cacheable object previously found with find() or findCached().
 void remove(Cacheable entry)
          Delete and remove an object from the cache.
 void resetCacheStats()
          reset the cache statistics to 0.
 void resize(long newSize)
          Change the maximum size of the cache.
 void scan(org.apache.derby.iapi.util.Matchable filter, org.apache.derby.iapi.util.Operator operator)
          Perform an operation on (approximately) all entries that matches the filter, or all entries if the filter is null.
 void setUsed(java.lang.Object[] keys)
          Mark a set of entries as having been used.
 void shutdown()
          Shutdown the cache.
 void useDaemonService(org.apache.derby.iapi.services.daemon.DaemonService daemon)
          This cache can use this DaemonService if it needs some work to be done int he background
 

Method Detail

getMaximumSize

public long getMaximumSize()

resize

public void resize(long newSize)
            throws org.apache.derby.iapi.error.StandardException
Change the maximum size of the cache. If the size is decreased then cache entries will be thrown out.


find

public Cacheable find(java.lang.Object key)
               throws org.apache.derby.iapi.error.StandardException
Find an object in the cache.

Find an object in the cache that matches the key provided using the equals() method, i.e. the return Cacheable will have getIdentifier.equals(key) true. If the object does not exist in the cache it will be added by one of:

  • creating a new holder object and calling its initParameter() method and then its setIdentity() method with key as the parameter.
  • Calling clearIdentity() on an holder object in the clean state and then calling its setIdentity() method with key as the parameter.
  • Calling clean() on a dirty holder object and then calling clearIdentity() on an holder object in the clean state and then calling its setIdentity() method with key as the parameter.
In all cases the setIdentity() method is called with forCreate set to false.
The returned object is kept, i.e. its identity will not change, until the release() method is called. The release() method must be called after the caller is finished with the object and throw away the reference to it, e.g.
                        Page p = (Page) pageCache.find(pageKey);

                        // do stuff with p

                        // release p
                        pageCache.release(p);
                        p = null;

                


findCached

public Cacheable findCached(java.lang.Object key)
                     throws org.apache.derby.iapi.error.StandardException
Find an object in the cache.

Find an object in the cache that matches the key provided using the equals() method, i.e. the return Cacheable will have getIdentifier.equals(key) true. If a matching object does not exist in the cache, null is returned.
The returned object is kept, i.e. its identity will not change, until the release() method is called. The release() method must be called after the caller is finished with the object and throw away the reference to it, e.g.

                        Page p = (Page) pageCache.findCached(pageKey);
                        if (p != null) {

                                // do stuff with p

                                // release p
                                pageCache.release(p);
                                p = null;
                        }

                


containsKey

public boolean containsKey(java.lang.Object key)
Determine whether a key is in the cache. WARNING: This method does not keep a lock on the entry or the cache, so the return value could be made incorrect by the time that this method returns. Therefore this method should only be used for statistical purposes.


setUsed

public void setUsed(java.lang.Object[] keys)
Mark a set of entries as having been used. Normally this is done as a side effect of find() or findCached. If the entry has been replaced then this method does nothing.


create

public Cacheable create(java.lang.Object key,
                        java.lang.Object createParameter)
                 throws org.apache.derby.iapi.error.StandardException
Create an object in the cache. The resulting object will match the key provided using the equals() method, i.e. the return Cacheable will have getIdentifier.equals(key) true. If an object that matches the key already exists in the cache then an exception is thrown.
The object will be added by one of:
  • creating a new holder object and calling its initParameter() method and then its createIdentity() method with key as the parameter.
  • Calling clearIdentity() on an holder object in the clean state and then calling its createIdentity() method with key as the parameter.
  • Calling clean() on a dirty holder object and then calling clearIdentity() on an holder object in the clean state and then calling its createIdentity() method with key as the parameter.
In all cases the setIdentity() method is called with the createParameter as the second argument. If the object cannot be created then an exception is thrown by createIdentity.
The returned object is kept, i.e. its identity will not change, until the release() method is called. The release() method must be called after the caller is finished with the object and throw away the reference to it, e.g.
                        Page p = (Page) pageCache.create(pageKey, createType);

                        // do stuff with p

                        // release p
                        pageCache.release(p);
                        p = null;

                


release

public void release(Cacheable entry)
Release a Cacheable object previously found with find() or findCached(). After this call the caller must throw away the reference to item.


remove

public void remove(Cacheable entry)
            throws org.apache.derby.iapi.error.StandardException
Delete and remove an object from the cache. It is up to the user of the cache to provide synchronization of some form that ensures that only one caller executes remove() on a cached object.
The object must have previously been found with find() or findCached(). The item will be placed into the NoIdentity state through clean(true) (if required) and clearIdentity(). The removal of the object will be delayed until it is not kept by anyone. Objects that are in the to be removed state can still be found through find() and findCached() until their keep count drops to zero. This call waits until the object has been removed.
After this call the caller must throw away the reference to item.


cleanAll

public void cleanAll()
              throws org.apache.derby.iapi.error.StandardException
Place all objects in their clean state by calling their clean method if they are dirty. This method guarantees that all objects that existed in the cache at the time of the call are placed in the clean state sometime during this call. Objects that are added to the cache during this call or objects that are dirtied during this call (by other callers) are not guaranteed to be clean once this call returns.


clean

public void clean(org.apache.derby.iapi.util.Matchable partialKey)
           throws org.apache.derby.iapi.error.StandardException
Clean all objects that match the partialKey (or exact key). Any cached object that results in the partialKey.equals(Object) method returning true when passed the cached object will be cleaned.

In order to clean more than one object the Cacheable equals method must be able to handle a partial key, e.g. a page has PageKey but a clean may pass a ContainerKey which will discard all pages in that container.


ageOut

public void ageOut()
Age as many objects as possible out of the cache. This call is guaranteed not to block. It is not guaranteed to leave the cache empty.
It is guaranteed that all unkept, clean objects will be removed from the cache.


shutdown

public void shutdown()
              throws org.apache.derby.iapi.error.StandardException
Shutdown the cache. This call stops the cache returning any more valid references on a find() or findCached() call, and then cleanAll() and ageOut() are called. The cache remains in existence until the last kept object has been unkept.


useDaemonService

public void useDaemonService(org.apache.derby.iapi.services.daemon.DaemonService daemon)
This cache can use this DaemonService if it needs some work to be done int he background


discard

public boolean discard(org.apache.derby.iapi.util.Matchable partialKey)
Discard all objects that match the partialKey (or exact key). Any cached object that results in the partialKey.equals(Object) method returning true when passed the cached object will be thrown out of the cache if and only if it is not in use. The Cacheable will be discarded without its clean method being called.

If partialKey is null, it matches all objects. This is a way to discard all objects from the cache in case of emergency shutdown.

In order to discard more than one object the Cacheable equals method must be able to handle a partial key, e.g. a page has PageKey but a discard may pass a ContainerKey which will discard all pages in that container.


getNumberInUse

public int getNumberInUse()
Report the number of items in use (with Identity) in this cache.


getCacheStats

public long[] getCacheStats()
Return statistics about cache that may be implemented.


resetCacheStats

public void resetCacheStats()
reset the cache statistics to 0.


scan

public void scan(org.apache.derby.iapi.util.Matchable filter,
                 org.apache.derby.iapi.util.Operator operator)
Perform an operation on (approximately) all entries that matches the filter, or all entries if the filter is null. Entries that are added while the cache is being scanned might or might not be missed.