public abstract class Cache<K,V> extends Object implements SizeMeasurable, Map<K,V>, CacheMBean
| Modifier and Type | Field and Description |
|---|---|
protected Object |
lock |
protected int |
maxEntrySize |
| Constructor and Description |
|---|
Cache(int size) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
checkCachePolicy(Object key)
Checks whether the key object should be cached.
|
void |
clear() |
boolean |
contains(Object key) |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
boolean |
equals(Object o) |
V |
get(Object key)
Like 'get' of Maps but considers if the cache is active or not, and the cache policy of the key.
|
double |
getAvarageValueLength()
Returns the average 'length' of the values in the cache.
|
int |
getByteSize()
Determines the byte-size of this object
|
int |
getByteSize(SizeOf sizeof)
Determines the byte-size of this object using the given SizeOf instance.
|
int |
getCheapByteSize()
Returns the sum of bytesizes of every key and value.
|
int |
getCount(K key) |
protected int |
getDefaultMaxEntrySize()
This has to be overridden by Caches which support max entry size.
|
String |
getDescription()
Gives a description for this cache type.
|
long |
getHits()
Returns the number of times an element was succesfully retrieved
from the table.
|
Class<?> |
getImplementation() |
Object |
getLock()
If you want to structurally modify this cache, synchronize on this object.
|
int |
getMaxEntrySize()
Return the maximum entry size for the cache in bytes.
|
int |
getMaxSize() |
long |
getMisses()
Returns the number of times an element cpould not be retrieved
from the table.
|
String |
getName()
Returns a name for this cache type.
|
long |
getPuts()
Returns the number of times an element was committed to the table.
|
double |
getRatio()
Returns the ratio of hits and misses.
|
int |
getSize() |
String |
getStats()
Returns statistics on this table.
|
int |
hashCode() |
boolean |
isActive()
Wether this cache is active or not.
|
boolean |
isEmpty() |
Set<K> |
keySet() |
int |
maxSize() |
V |
put(K key,
V value)
Like 'put' of LRUHashtable but considers if the cache is active or not.
|
void |
putAll(Map<? extends K,? extends V> t) |
Cache<K,V> |
putCache()
Puts this cache in the caches repository.
|
V |
remove(Object key) |
void |
reset()
Reset 'puts', 'misses' and 'puts' to 0.
|
void |
setActive(boolean a)
Sets this cache to active or passive.
|
(package private) void |
setImplementation(String clazz,
Map<String,String> configValues) |
void |
setMaxEntrySize(int i) |
void |
setMaxSize(int size) |
int |
size() |
String |
toString() |
Collection<V> |
values() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllprotected int maxEntrySize
protected volatile Object lock
public final Object getLock()
public String getName()
getName in interface CacheMBeanpublic String getDescription()
getDescription in interface CacheMBeanpublic int getMaxEntrySize()
getMaxEntrySize in interface CacheMBeangetMaxEntrySize()public void setMaxEntrySize(int i)
setMaxEntrySize in interface CacheMBeansetMaxEntrySize(int)public double getAvarageValueLength()
QueryResultCache the length obviously is the length of the cached lists.
May return NaN if unknown or undetermined.getAvarageValueLength in interface CacheMBeanprotected int getDefaultMaxEntrySize()
public Class<?> getImplementation()
protected boolean checkCachePolicy(Object key)
false if either the current cache is inactive, or the object to cache
has a cache policy associated that prohibits caching of the object.key - the object to be cachedtrue if the object can be cachedpublic V get(Object key)
public V put(K key, V value)
public long getHits()
getHits in interface CacheMBeangetHits()public long getMisses()
getMisses in interface CacheMBeangetMisses()public long getPuts()
getPuts in interface CacheMBeangetPuts()public void reset()
reset in interface CacheMBeanreset()public void setMaxSize(int size)
setMaxSize in interface CacheMBeanpublic int maxSize()
public int getMaxSize()
getMaxSize in interface CacheMBeangetMaxSize()public int size()
size in interface Map<K,V>Map.size()public int getSize()
getSize in interface CacheMBeangetSize()public boolean contains(Object key)
public int getCount(K key)
public double getRatio()
getRatio in interface CacheMBeangetRatio()public String getStats()
public void setActive(boolean a)
setActive in interface CacheMBeanisActive()public final boolean isActive()
isActive in interface CacheMBeanpublic int getByteSize()
SizeMeasurablegetByteSize in interface CacheMBeangetByteSize in interface SizeMeasurablepublic int getByteSize(SizeOf sizeof)
SizeMeasurablegetByteSize in interface SizeMeasurablepublic int getCheapByteSize()
getByteSize(), which has to keep a Collection of every counted object.public void clear()
clear in interface Map<K,V>clear in interface CacheMBeanMap.clear()public boolean containsKey(Object key)
containsKey in interface Map<K,V>Map.containsKey(java.lang.Object)public boolean containsValue(Object value)
containsValue in interface Map<K,V>Map.containsValue(java.lang.Object)public boolean equals(Object o)
public int hashCode()
public boolean isEmpty()
isEmpty in interface Map<K,V>Map.isEmpty()public void putAll(Map<? extends K,? extends V> t)
putAll in interface Map<K,V>Map.putAll(java.util.Map)public V remove(Object key)
remove in interface Map<K,V>Map.remove(java.lang.Object)public Collection<V> values()
values in interface Map<K,V>Map.values()public Cache<K,V> putCache()
CacheManager.putCache(Cache)MMBase 1.9-SNAPSHOT - ${javadoctimestamp}