wt.pom
Class RefreshCache

java.lang.Object
  extended bywt.pom.RefreshCache

public class RefreshCache
extends Object

A fixed size, most recently used object cache. The caches size is set at construction, and only the most recently used entries are maintained. Each get or put operation makes that entry the most recently used. When putting new entries, if the cache is full, the least recently used entry is aged out of the cache.

Supported API: false
Extendable: false


Nested Class Summary
(package private)  class RefreshCache.RefreshCacheListener
           
 
Field Summary
protected  int agedOut
           
protected  int cacheSize
           
protected  int count
           
protected  int[] hashCodes
           
protected  int hits
           
protected  Object[] keys
           
private  int leastRecentlyUsed
           
private  RefreshCache.RefreshCacheListener listener
           
protected  int misses
           
private  int mostRecentlyUsed
           
private  short[] newer
           
private  short[] next
           
private  short[] older
           
private  short[] prev
           
private static String RESOURCE
           
protected  int tableSize
           
protected  Object[] values
           
private static String versionID
           
 
Constructor Summary
RefreshCache(int size)
          Construct a new fixed-size, most-recently-used cache.
 
Method Summary
 void clear()
          Clears the cache.
 boolean containskey(ObjectIdentifier key)
          check if the specified key exists

Supported API: true
 Enumeration entries()
          Returns an Enumeration of the entries in the cache.
protected  int find(Object key)
          Protected method that finds existing entry.
 Object get(ObjectIdentifier key)
          Get an entry from the cache.
 Object[] getKeys()
           
protected  POMOperationListener getPOMOperationListener()
           
protected  int link(Object key)
          Protected method that finds slot for an existing or new entry.
protected  void overflow(Object key, Object value)
          Called when an entry is being aged out of the cache.
protected  void print()
           
 void put(ObjectIdentifier key, Persistable value)
          Put an entry in the cache.
protected  void registerRefreshCacheListener()
           
 void remove(ObjectIdentifier key)
          Remove an entry from the cache.
 String toString()
          Returns string representation of the cache.
protected  void touch(int index)
          Protected method to update age links to make the given entry be the most recently used.
private  void unlink(int index)
          Protected method to unlink an entry from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

versionID

private static final String versionID
See Also:
Constant Field Values

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

cacheSize

protected int cacheSize

tableSize

protected int tableSize

count

protected int count

keys

protected Object[] keys

values

protected Object[] values

hashCodes

protected int[] hashCodes

hits

protected int hits

misses

protected int misses

agedOut

protected int agedOut

mostRecentlyUsed

private int mostRecentlyUsed

leastRecentlyUsed

private int leastRecentlyUsed

newer

private short[] newer

older

private short[] older

next

private short[] next

prev

private short[] prev

listener

private RefreshCache.RefreshCacheListener listener
Constructor Detail

RefreshCache

public RefreshCache(int size)
Construct a new fixed-size, most-recently-used cache. Sparse arrays of shorts are used to maintain linked lists in a memory efficient manner - the maximum size supported by this implementation is 10922.

Supported API: true

Parameters:
size - the maximum number of entries stored in the cache.
Method Detail

containskey

public boolean containskey(ObjectIdentifier key)
check if the specified key exists

Supported API: true

Parameters:
key - the entry key
Returns:
boolean indicate if the specified key exists

get

public Object get(ObjectIdentifier key)
Get an entry from the cache. Hit and miss statistics are updated.

Supported API: true

Parameters:
key - the entry key
Returns:
the cached object or null if not found

put

public void put(ObjectIdentifier key,
                Persistable value)
Put an entry in the cache. If an entry for the given key already exists, the previous value is discarded. This entry is considered the most recently used.

Supported API: true

Parameters:
key - the entry key
value - the value to associate with the given key

remove

public void remove(ObjectIdentifier key)
Remove an entry from the cache. Does nothing if the entry is not currently in the cache.

Supported API: true

Parameters:
key - the entry key

clear

public void clear()
Clears the cache. All entries are removed.

Supported API: true


find

protected int find(Object key)
Protected method that finds existing entry. Hit and miss statistics are not updated. Most recently used list is not updated.

Supported API: false

Parameters:
key - the entry key
Returns:
index of the entry or 0 if not found

link

protected int link(Object key)
Protected method that finds slot for an existing or new entry. Hit and miss statistics are not updated. Most recently used list is not updated.

Supported API: false

Parameters:
key - the entry key
Returns:
index of the entry

touch

protected void touch(int index)
Protected method to update age links to make the given entry be the most recently used.

Supported API: false

Parameters:
index - the index of the entry

unlink

private void unlink(int index)
Protected method to unlink an entry from the cache.

Supported API: false

Parameters:
index - the index of the entry

entries

public Enumeration entries()
Returns an Enumeration of the entries in the cache.

Supported API: true


toString

public String toString()
Returns string representation of the cache. The string contains the default string representation of the object plus a summary of the current cache size, hits and misses counts, and aged out entry count.

Supported API: true


overflow

protected void overflow(Object key,
                        Object value)
Called when an entry is being aged out of the cache. Can be overriden by subclasses that want to take some action when an entry is being aged out of the cache due to overflow. It is only called when an entry is aged out due to overflow, not when entries are explicitly removed or the cache is cleared. It is called before the entry is removed from the cache.

Parameters:
key - the entry key
value - the entry value

print

protected void print()

getKeys

public Object[] getKeys()

getPOMOperationListener

protected POMOperationListener getPOMOperationListener()

registerRefreshCacheListener

protected void registerRefreshCacheListener()
                                     throws PersistenceException
Throws:
PersistenceException