Package org.jivesoftware.util.cache
Class CacheWrapper<K extends Serializable,V extends Serializable>
- java.lang.Object
-
- org.jivesoftware.util.cache.CacheWrapper<K,V>
-
- Direct Known Subclasses:
ComponentCacheWrapper
public class CacheWrapper<K extends Serializable,V extends Serializable> extends Object implements Cache<K,V>
Acts as a proxy for a Cache implementation. The Cache implementation can be switched on the fly, which enables users to hold a reference to a CacheWrapper object, but for the underlying Cache implementation to switch from clustered to local, etc.
-
-
Field Summary
-
Fields inherited from interface org.jivesoftware.util.cache.Cache
secretKey, secretValue
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)Set<Map.Entry<K,V>>entrySet()IMPORTANT: Unlike the standardMap.entrySet()implementation, the set returned from this method cannot be modified.Vget(Object key)longgetCacheHits()Returns the number of cache hits.longgetCacheMisses()Returns the number of cache misses.intgetCacheSize()Returns the size of the cache contents in bytes limited to integer size.longgetLongCacheSize()Returns the size of the cache contents in bytes.longgetMaxCacheSize()Returns the maximum size of the cache in bytes.longgetMaxLifetime()Returns the maximum number of milliseconds that any object can live in cache.StringgetName()Returns the name of the cache.Cache<K,V>getWrappedCache()booleanisEmpty()Set<K>keySet()IMPORTANT: Unlike the standardMap.keySet()implementation, the set returned from this method cannot be modified.Vput(K key, V value)voidputAll(Map<? extends K,? extends V> t)Vremove(Object key)voidsetMaxCacheSize(int maxSize)Sets the maximum size of the cache in bytes limited to integer size.voidsetMaxCacheSize(long maxSize)Sets the maximum size of the cache in bytes.voidsetMaxLifetime(long maxLifetime)Sets the maximum number of milliseconds that any object can live in cache.voidsetName(String name)Sets the name of the cacheintsize()Collection<V>values()IMPORTANT: Unlike the standardMap.values()implementation, the collection returned from this method cannot be modified.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.util.cache.Cache
getLock, isKeySecret, isValueSecret, setSecretKey, setSecretValue
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:CacheReturns the name of the cache.- Specified by:
getNamein interfaceCache<K extends Serializable,V extends Serializable>- Returns:
- the name of the cache.
-
setName
public void setName(String name)
Description copied from interface:CacheSets the name of the cache- Specified by:
setNamein interfaceCache<K extends Serializable,V extends Serializable>- Parameters:
name- the name of the cache
-
getMaxCacheSize
public long getMaxCacheSize()
Description copied from interface:CacheReturns the maximum size of the cache in bytes. If the cache grows larger than the max size, the least frequently used items will be removed. If the max cache size is set to -1, there is no size limit.- Specified by:
getMaxCacheSizein interfaceCache<K extends Serializable,V extends Serializable>- Returns:
- the maximum size of the cache in bytes.
-
setMaxCacheSize
public void setMaxCacheSize(int maxSize)
Description copied from interface:CacheSets the maximum size of the cache in bytes limited to integer size. If the cache grows larger than the max size, the least frequently used items will be removed. If the max cache size is set to -1, there is no size limit.Note: If using the Hazelcast clustering plugin, this will not take effect until the next time the cache is created
- Specified by:
setMaxCacheSizein interfaceCache<K extends Serializable,V extends Serializable>- Parameters:
maxSize- the maximum size of the cache in bytes.
-
setMaxCacheSize
public void setMaxCacheSize(long maxSize)
Description copied from interface:CacheSets the maximum size of the cache in bytes. If the cache grows larger than the max size, the least frequently used items will be removed. If the max cache size is set to -1, there is no size limit.Note: If using the Hazelcast clustering plugin, this will not take effect until the next time the cache is created
Attention: The default implementation of this method sets the cache value limited to integer size.- Specified by:
setMaxCacheSizein interfaceCache<K extends Serializable,V extends Serializable>- Parameters:
maxSize- the maximum size of the cache in bytes.
-
getMaxLifetime
public long getMaxLifetime()
Description copied from interface:CacheReturns the maximum number of milliseconds that any object can live in cache. Once the specified number of milliseconds passes, the object will be automatically expired from cache. If the max lifetime is set to -1, then objects never expire.- Specified by:
getMaxLifetimein interfaceCache<K extends Serializable,V extends Serializable>- Returns:
- the maximum number of milliseconds before objects are expired.
-
setMaxLifetime
public void setMaxLifetime(long maxLifetime)
Description copied from interface:CacheSets the maximum number of milliseconds that any object can live in cache. Once the specified number of milliseconds passes, the object will be automatically expired from cache. If the max lifetime is set to -1, then objects never expire.Note: If using the Hazelcast clustering plugin, this will not take effect until the next time the cache is created
- Specified by:
setMaxLifetimein interfaceCache<K extends Serializable,V extends Serializable>- Parameters:
maxLifetime- the maximum number of milliseconds before objects are expired.
-
getCacheSize
public int getCacheSize()
Description copied from interface:CacheReturns the size of the cache contents in bytes limited to integer size. This value is only a rough approximation, so cache users should expect that actual VM memory used by the cache could be significantly higher than the value reported by this method.- Specified by:
getCacheSizein interfaceCache<K extends Serializable,V extends Serializable>- Returns:
- the size of the cache contents in bytes.
-
getLongCacheSize
public long getLongCacheSize()
Description copied from interface:CacheReturns the size of the cache contents in bytes. This value is only a rough approximation, so cache users should expect that actual VM memory used by the cache could be significantly higher than the value reported by this method. Attention: The default implementation of this method returns the cache value limited to integer size.- Specified by:
getLongCacheSizein interfaceCache<K extends Serializable,V extends Serializable>- Returns:
- the size of the cache contents in bytes.
-
getCacheHits
public long getCacheHits()
Description copied from interface:CacheReturns the number of cache hits. A cache hit occurs every time the get method is called and the cache contains the requested object.Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient.
- Specified by:
getCacheHitsin interfaceCache<K extends Serializable,V extends Serializable>- Returns:
- the number of cache hits.
-
getCacheMisses
public long getCacheMisses()
Description copied from interface:CacheReturns the number of cache misses. A cache miss occurs every time the get method is called and the cache does not contain the requested object.Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient.
- Specified by:
getCacheMissesin interfaceCache<K extends Serializable,V extends Serializable>- Returns:
- the number of cache hits.
-
size
public int size()
- Specified by:
sizein interfaceMap<K extends Serializable,V extends Serializable>
-
clear
public void clear()
- Specified by:
clearin interfaceMap<K extends Serializable,V extends Serializable>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceMap<K extends Serializable,V extends Serializable>
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<K extends Serializable,V extends Serializable>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<K extends Serializable,V extends Serializable>
-
values
public Collection<V> values()
Description copied from interface:CacheIMPORTANT: Unlike the standardMap.values()implementation, the collection returned from this method cannot be modified.- Specified by:
valuesin interfaceCache<K extends Serializable,V extends Serializable>- Specified by:
valuesin interfaceMap<K extends Serializable,V extends Serializable>- Returns:
- an unmodifiable collection view of the values contained in this map
-
putAll
public void putAll(Map<? extends K,? extends V> t)
- Specified by:
putAllin interfaceMap<K extends Serializable,V extends Serializable>
-
entrySet
public Set<Map.Entry<K,V>> entrySet()
Description copied from interface:CacheIMPORTANT: Unlike the standardMap.entrySet()implementation, the set returned from this method cannot be modified.- Specified by:
entrySetin interfaceCache<K extends Serializable,V extends Serializable>- Specified by:
entrySetin interfaceMap<K extends Serializable,V extends Serializable>- Returns:
- an unmodifiable set view of the mappings contained in this map
-
keySet
public Set<K> keySet()
Description copied from interface:CacheIMPORTANT: Unlike the standardMap.keySet()implementation, the set returned from this method cannot be modified.- Specified by:
keySetin interfaceCache<K extends Serializable,V extends Serializable>- Specified by:
keySetin interfaceMap<K extends Serializable,V extends Serializable>- Returns:
- an unmodifiable set view of the keys contained in this map
-
get
public V get(Object key)
- Specified by:
getin interfaceMap<K extends Serializable,V extends Serializable>
-
remove
public V remove(Object key)
- Specified by:
removein interfaceMap<K extends Serializable,V extends Serializable>
-
put
public V put(K key, V value)
- Specified by:
putin interfaceMap<K extends Serializable,V extends Serializable>
-
-