public class CacheMap
extends java.lang.Object
implements java.util.Map
Modifier and Type | Field and Description |
---|---|
protected SizedMap |
cacheMap
The map for non-expired and non-pinned references.
|
protected java.util.Map |
pinnedMap
The set of objects pinned into the cache.
|
protected SizedMap |
softMap
The map for expired references.
|
Constructor and Description |
---|
CacheMap()
Create a non-LRU (and therefore highly concurrent) cache map with a
size of 1000.
|
CacheMap(boolean lru)
Create a cache map with a size of 1000.
|
CacheMap(boolean lru,
int max)
Create a cache map with the given properties.
|
CacheMap(boolean lru,
int max,
int size,
float load)
Deprecated.
use
CacheMap(boolean, int, int, float, int)
instead. |
CacheMap(boolean lru,
int max,
int size,
float load,
int concurrencyLevel)
Create a cache map with the given properties.
|
Modifier and Type | Method and Description |
---|---|
protected void |
cacheMapOverflowRemoved(java.lang.Object key,
java.lang.Object value)
Called from
SizedMap.overflowRemoved(java.lang.Object, java.lang.Object) in the cache map. |
void |
clear()
Removes pinned objects as well as unpinned ones.
|
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object val) |
protected void |
entryAdded(java.lang.Object key,
java.lang.Object value)
Invoked when an entry is added to the cache.
|
protected void |
entryRemoved(java.lang.Object key,
java.lang.Object value,
boolean expired)
Invoked when a key-value pair is evicted from this data
structure.
|
java.util.Set |
entrySet() |
java.lang.Object |
get(java.lang.Object key) |
int |
getCacheSize()
The maximum number of hard references to maintain, or -1 for no limit.
|
java.util.Set |
getPinnedKeys()
The keys pinned into the map.
|
int |
getSoftReferenceSize()
The maximum number of soft references to maintain, or -1 for no limit.
|
boolean |
isEmpty() |
boolean |
isLRU()
Whether this cache map uses LRU eviction.
|
java.util.Set |
keySet() |
boolean |
pin(java.lang.Object key)
Locks the given key and its value into the map.
|
protected java.lang.Object |
put(java.util.Map map,
java.lang.Object key,
java.lang.Object value)
Put the given entry into the given map.
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value) |
void |
putAll(java.util.Map map) |
void |
putAll(java.util.Map map,
boolean replaceExisting) |
void |
readLock()
Acquire read lock.
|
void |
readUnlock()
Release read lock.
|
protected java.lang.Object |
remove(java.util.Map map,
java.lang.Object key)
Remove the given key from the given map.
|
java.lang.Object |
remove(java.lang.Object key)
If
key is pinned into the cache, the pin is
cleared and the object is removed. |
void |
setCacheSize(int size)
The maximum number of hard references to maintain, or -1 for no limit.
|
void |
setSoftReferenceSize(int size)
The maximum number of soft references to maintain, or -1 for no limit.
|
int |
size() |
protected void |
softMapOverflowRemoved(java.lang.Object key,
java.lang.Object value)
Called from
SizedMap.overflowRemoved(java.lang.Object, java.lang.Object) in the soft map. |
protected void |
softMapValueExpired(java.lang.Object key)
Called when a value expires from the soft map.
|
java.lang.String |
toString() |
boolean |
unpin(java.lang.Object key)
Undo a pinning.
|
java.util.Collection |
values() |
void |
writeLock()
Acquire write lock.
|
void |
writeUnlock()
Release write lock.
|
protected final SizedMap cacheMap
protected final SizedMap softMap
protected final java.util.Map pinnedMap
public CacheMap()
public CacheMap(boolean lru)
lru
- if true, create a LRU cache map otherwise a non-LRU map will be created.public CacheMap(boolean lru, int max)
public CacheMap(boolean lru, int max, int size, float load)
CacheMap(boolean, int, int, float, int)
instead.public CacheMap(boolean lru, int max, int size, float load, int concurrencyLevel)
protected void cacheMapOverflowRemoved(java.lang.Object key, java.lang.Object value)
SizedMap.overflowRemoved(java.lang.Object, java.lang.Object)
in the cache map.protected void softMapOverflowRemoved(java.lang.Object key, java.lang.Object value)
SizedMap.overflowRemoved(java.lang.Object, java.lang.Object)
in the soft map.protected void softMapValueExpired(java.lang.Object key)
protected java.lang.Object put(java.util.Map map, java.lang.Object key, java.lang.Object value)
protected java.lang.Object remove(java.util.Map map, java.lang.Object key)
public void readLock()
public void readUnlock()
public void writeLock()
public void writeUnlock()
public boolean isLRU()
public void setCacheSize(int size)
public int getCacheSize()
public void setSoftReferenceSize(int size)
public int getSoftReferenceSize()
public java.util.Set getPinnedKeys()
public boolean pin(java.lang.Object key)
public boolean unpin(java.lang.Object key)
protected void entryRemoved(java.lang.Object key, java.lang.Object value, boolean expired)
expired
set to
true
when an object is dropped because of space
requirements or through garbage collection of soft references.
It is invoked with expired
set to false
when an object is explicitly removed via the remove(java.util.Map, java.lang.Object)
or
clear()
methods. This may be invoked more than once for a
given entry.value
- may be null if the value was a soft reference that has
been GCdprotected void entryAdded(java.lang.Object key, java.lang.Object value)
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
public void putAll(java.util.Map map)
putAll
in interface java.util.Map
public void putAll(java.util.Map map, boolean replaceExisting)
public java.lang.Object remove(java.lang.Object key)
key
is pinned into the cache, the pin is
cleared and the object is removed.remove
in interface java.util.Map
public void clear()
clear
in interface java.util.Map
public int size()
size
in interface java.util.Map
public boolean isEmpty()
isEmpty
in interface java.util.Map
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
public boolean containsValue(java.lang.Object val)
containsValue
in interface java.util.Map
public java.util.Set keySet()
keySet
in interface java.util.Map
public java.util.Collection values()
values
in interface java.util.Map
public java.util.Set entrySet()
entrySet
in interface java.util.Map
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2006-2013 Apache Software Foundation. All Rights Reserved.