Top Description Methods
org.glassfish.hk2.utilities.cache

public Interface WeakCARCache<K, V>

Known Direct Implementers
org.glassfish.hk2.utilities.cache.internal.WeakCARCacheImpl

A cache that uses the CAR algorithm to remove entries.

As a quick review, the CAR algorithm maintains four lists:

  1. t1 - A clock of recently used keys with values
  2. t2 - A clock of frequently used keys with values
  3. b1 - A LRU of keys removed from t1 with no values
  4. b2 - A LRU of keys removed from t2 with no values
The sum of entries in t1 and t2 will never be higher than maxSize (c). The sum of entries in all four lists will never be higher than 2c. There is an adaptive parameter p which is the target size of the t1 list which gets modified when a key is found on either the b1 or b2 list. This adaptive parameter essentially allows the algorithm to adapt to the pattern of keys, whether there be more frequently used keys or there be a pattern of keys used quickly but not again.
Author
jwells

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Clears the current cache, making the current size zero

public void
clearStaleReferences()

Causes stale references to be cleared from the data structures.

public V

Returns:

The calculated return value. May not be null
compute
(K
The key to add to the cache. If the value is not found, then the computable will be called to get the value. May not be null
key
)

The method used to get or add values to this cache

public String

Returns:

A String containing the values of T1, T2, B1 and B2
dumpAllLists
()

Returns a string that will contain all the elements of the four lists

public int

Returns:

The current number of items in the B1 LRU
getB1Size
()

Returns the number of items in the B1 LRU

public int

Returns:

The current number of items in the B2 LRU
getB2Size
()

Returns the number of items in the B2 LRU

public Computable<K, V>

Returns:

The computable associated with this cache
getComputable
()

The computable associated with this cache

public double

Returns:

The Hit rate from the last time clear was called or 0 if there is no data
getHitRate
()

Returns the hit rate from the last time clear was called

public int

Returns:

The current number of key entries in the cache
getKeySize
()

Returns the current number of keys in the cache.

public int

Returns:

The maximum size of the cache
getMaxSize
()

Gets the current maximum size of the cache (the maximum number of values that will be kept by the cache).

public int

Returns:

The current value of P
getP
()

Returns the value of p from the CAR algorithm, which is the target size of the t1 clock

public int

Returns:

The current number of items in the T1 clock
getT1Size
()

Returns the number of items in the T1 clock

public int

Returns:

The current number of items in the T2 clock
getT2Size
()

Returns the number of items in the T2 clock

public int

Returns:

The current number of value entries in the cache
getValueSize
()

Returns the current number of values in the cache.

public void
releaseMatching(CacheKeyFilter<K>
A non-null filter that can be used to delete every key/value pair that matches the filter
filter
)

Releases all key/value pairs that match the filter

public boolean

Returns:

true if a key was found and removed
remove
(K
The key to remove. May not be null
key
)

Used to remove a single key and value from the cache (if the value is available)

Method Detail

clearback to summary
public void clear()

Clears the current cache, making the current size zero

clearStaleReferencesback to summary
public void clearStaleReferences()

Causes stale references to be cleared from the data structures. Since this is a weak cache the references can go away at any time, which happens whenever any operation has been performed. However, it may be the case that no operation will be performed for a while and so this method is provided to have a no-op operation to call in order to clear out any stale references

computeback to summary
public V compute(K key)

The method used to get or add values to this cache

Parameters
key:K

The key to add to the cache. If the value is not found, then the computable will be called to get the value. May not be null

Returns:V

The calculated return value. May not be null

dumpAllListsback to summary
public String dumpAllLists()

Returns a string that will contain all the elements of the four lists

Returns:String

A String containing the values of T1, T2, B1 and B2

getB1Sizeback to summary
public int getB1Size()

Returns the number of items in the B1 LRU

Returns:int

The current number of items in the B1 LRU

getB2Sizeback to summary
public int getB2Size()

Returns the number of items in the B2 LRU

Returns:int

The current number of items in the B2 LRU

getComputableback to summary
public Computable<K, V> getComputable()

The computable associated with this cache

Returns:Computable<K, V>

The computable associated with this cache

getHitRateback to summary
public double getHitRate()

Returns the hit rate from the last time clear was called

Returns:double

The Hit rate from the last time clear was called or 0 if there is no data

getKeySizeback to summary
public int getKeySize()

Returns the current number of keys in the cache. Note that the number of keys can be up to 2x the maximum size of the cache

Returns:int

The current number of key entries in the cache

getMaxSizeback to summary
public int getMaxSize()

Gets the current maximum size of the cache (the maximum number of values that will be kept by the cache). Note that the number of keys kept will be 2x, where x is the maximum size of the cache (see CAR algorithm which keeps a key history)

Returns:int

The maximum size of the cache

getPback to summary
public int getP()

Returns the value of p from the CAR algorithm, which is the target size of the t1 clock

Returns:int

The current value of P

getT1Sizeback to summary
public int getT1Size()

Returns the number of items in the T1 clock

Returns:int

The current number of items in the T1 clock

getT2Sizeback to summary
public int getT2Size()

Returns the number of items in the T2 clock

Returns:int

The current number of items in the T2 clock

getValueSizeback to summary
public int getValueSize()

Returns the current number of values in the cache. Note that the number of values can be up the maximum size of the cache

Returns:int

The current number of value entries in the cache

releaseMatchingback to summary
public void releaseMatching(CacheKeyFilter<K> filter)

Releases all key/value pairs that match the filter

Parameters
filter:CacheKeyFilter<K>

A non-null filter that can be used to delete every key/value pair that matches the filter

removeback to summary
public boolean remove(K key)

Used to remove a single key and value from the cache (if the value is available)

Parameters
key:K

The key to remove. May not be null

Returns:boolean

true if a key was found and removed