Package wt.util
Class Cache
java.lang.Object
java.util.AbstractMap
wt.util.Cache
- All Implemented Interfaces:
Map
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: true
Extendable: false
Supported API: true
Extendable: false
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the cache.entries()Deprecated.Get an entry from the cache.getAndRemove(Object key) Deprecated.getAndReplace(Object key, Object value) Deprecated.Put an entry in the cache.Remove an entry from the cache.toString()Returns string representation of the cache.Methods inherited from class java.util.AbstractMap
clone, isEmpty, putAll
-
Constructor Details
-
Cache
public Cache(int size) Construct a new fixed-size, most-recently-used cache. Sparse arrays of ints are used to maintain linked lists in a memory efficient manner - the maximum size supported by this implementation is 715827882.
Supported API: true- Parameters:
size- the maximum number of entries stored in the cache.
-
-
Method Details
-
get
Get an entry from the cache. Hit and miss statistics are updated.
Supported API: true- Specified by:
getin interfaceMap- Overrides:
getin classAbstractMap- Parameters:
key- the entry key- Returns:
- the cached object or null if not found
-
put
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- Specified by:
putin interfaceMap- Overrides:
putin classAbstractMap- Parameters:
key- the entry keyvalue- the value to associate with the given key- Returns:
- The previous value that mapped to the key, or null if there was no previous value
-
getAndReplace
Deprecated.Get an entry from the cache and replace it with a new entry. The new entry is considered the most recently used. Hit and miss statistics are updated.- Parameters:
key- the entry keyvalue- the value to associate with the given key- Returns:
- previous value
-
remove
Remove an entry from the cache. Does nothing if the entry is not currently in the cache.
Supported API: true- Specified by:
removein interfaceMap- Overrides:
removein classAbstractMap- Parameters:
key- the entry key
-
getAndRemove
Deprecated.Get an entry from the cache and remove it at the same time. Does nothing if the entry is not currently in the cache. Hit and miss statistics are updated.- Parameters:
key- the entry key- Returns:
- previous value
-
clear
public void clear()Clears the cache. All entries are removed.
Supported API: true- Specified by:
clearin interfaceMap- Overrides:
clearin classAbstractMap
-
entries
Deprecated.Replaced byvalues().iterator()
Supported API: trueReturns anEnumerationof the values in the cache. -
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- Overrides:
toStringin classAbstractMap
-
values().iterator()Supported API: true