Package org.jxmpp.util.cache
Class ExpirationCache<K,V>
- java.lang.Object
-
- org.jxmpp.util.cache.ExpirationCache<K,V>
-
- Type Parameters:
K- the type of the keys of this cache.V- the type of the values this cache caches.
- All Implemented Interfaces:
java.util.Map<K,V>,Cache<K,V>
public class ExpirationCache<K,V> extends java.lang.Object implements Cache<K,V>, java.util.Map<K,V>
A cache which expires its values.
-
-
Constructor Summary
Constructors Constructor Description ExpirationCache(int maxSize, long defaultExpirationTime)Construct a new expiration cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<K,V>>entrySet()Vget(java.lang.Object key)intgetMaxCacheSize()Return the maximum cache Size.booleanisEmpty()java.util.Set<K>keySet()Vlookup(K key)Returns the value of the specified key, ornull.Vput(K key, V value)Put a value in the cache.Vput(K key, V value, long expirationTime)Put a value in the cache with the specified expiration time in milliseconds.voidputAll(java.util.Map<? extends K,? extends V> m)Vremove(java.lang.Object key)Remove a entry with the given key from the cache.voidsetDefaultExpirationTime(long defaultExpirationTime)Set the default expiration time in milliseconds.voidsetMaxCacheSize(int maxCacheSize)Set the maximum cache size.intsize()java.util.Collection<V>values()
-
-
-
Method Detail
-
setDefaultExpirationTime
public final void setDefaultExpirationTime(long defaultExpirationTime)
Set the default expiration time in milliseconds.- Parameters:
defaultExpirationTime- the default expiration time.
-
put
public V put(K key, V value)
Description copied from interface:CachePut a value in the cache.
-
put
public V put(K key, V value, long expirationTime)
Put a value in the cache with the specified expiration time in milliseconds.- Parameters:
key- the key of the value.value- the value.expirationTime- the expiration time in milliseconds.- Returns:
- the previous value or
null.
-
lookup
public V lookup(K key)
Description copied from interface:CacheReturns the value of the specified key, ornull.
-
remove
public V remove(java.lang.Object key)
Remove a entry with the given key from the cache.
-
getMaxCacheSize
public int getMaxCacheSize()
Description copied from interface:CacheReturn the maximum cache Size.- Specified by:
getMaxCacheSizein interfaceCache<K,V>- Returns:
- the maximum cache size.
-
setMaxCacheSize
public void setMaxCacheSize(int maxCacheSize)
Description copied from interface:CacheSet the maximum cache size.- Specified by:
setMaxCacheSizein interfaceCache<K,V>- Parameters:
maxCacheSize- the new maximum cache size.
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
values
public java.util.Collection<V> values()
-
-