Package org.zkoss.util
Interface Cache<K,V>
- All Known Implementing Classes:
CacheMap,EmptyCacheMap,FastReadCache,MultiCache,ResourceCache
public interface Cache<K,V>
Represents a cache.
The interface is similar to java.util.Map but simpler to implement.
- Since:
- 3.0.0
- Author:
- tomyeh
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default minimal lifetime, unit=milliseconds.static final intThe default maximal allowed size. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all objects being cached.booleancontainsKey(Object key) Returns whether the specified key is stored.Returns the object of the specified key, or null if not found.intReturns the minimal lifetime, unit=milliseconds.intReturns the maximal allowed size.Stores an object to the cache.Removes an object from the cache.voidsetLifetime(int lifetime) Sets the minimal lifetime.voidsetMaxSize(int maxsize) Sets the maximal allowed size.
-
Field Details
-
DEFAULT_LIFETIME
static final int DEFAULT_LIFETIMEThe default minimal lifetime, unit=milliseconds. It is 30 minutes.- See Also:
-
DEFAULT_MAX_SIZE
static final int DEFAULT_MAX_SIZEThe default maximal allowed size. It is 512.- See Also:
-
-
Method Details
-
containsKey
Returns whether the specified key is stored. -
get
Returns the object of the specified key, or null if not found. -
put
Stores an object to the cache.- Returns:
- the previous value of the same, or null if no such value
-
remove
Removes an object from the cache.- Returns:
- the object if found.
-
clear
void clear()Clears all objects being cached. -
getLifetime
int getLifetime()Returns the minimal lifetime, unit=milliseconds. An mapping won't be removed by GC unless the minimal lifetime or the maximal allowed size exceeds.- See Also:
-
setLifetime
void setLifetime(int lifetime) Sets the minimal lifetime. Default:DEFAULT_LIFETIME.- Parameters:
lifetime- the lifetime, unit=milliseconds; if non-positive, they will be removed immediately.- See Also:
-
getMaxSize
int getMaxSize()Returns the maximal allowed size. Default:DEFAULT_MAX_SIZE. An mapping won't be removed by GC unless the minimal lifetime or the maximal allowed size exceeds.- See Also:
-
setMaxSize
void setMaxSize(int maxsize) Sets the maximal allowed size.- See Also:
-