org.zkoss.util
Interface Cache

All Known Implementing Classes:
CacheMap, MultiCache, ResourceCache, ThreadLocalCache

public interface Cache

Represents a cache. The interface is similar to java.util.Map but simpler to implement.

Since:
3.0.0
Author:
tomyeh

Field Summary
static int DEFAULT_LIFETIME
          The default minimal lifetime, unit=milliseconds.
static int DEFAULT_MAX_SIZE
          The default maximal allowed size.
 
Method Summary
 void clear()
          Clears all objects being cached.
 boolean containsKey(java.lang.Object key)
          Returns whether the specified key is stored.
 java.lang.Object get(java.lang.Object key)
          Returns the object of the specified key, or null if not found.
 int getLifetime()
          Returns the minimal lifetime, unit=milliseconds.
 int getMaxSize()
          Returns the maximal allowed size.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Stores an object to the cache.
 java.lang.Object remove(java.lang.Object key)
          Removes an object from the cache.
 void setLifetime(int lifetime)
          Sets the minimal lifetime.
 void setMaxSize(int maxsize)
          Sets the maximal allowed size.
 

Field Detail

DEFAULT_LIFETIME

static final int DEFAULT_LIFETIME
The default minimal lifetime, unit=milliseconds. It is 30 minutes.

See Also:
Constant Field Values

DEFAULT_MAX_SIZE

static final int DEFAULT_MAX_SIZE
The default maximal allowed size. It is 512.

See Also:
Constant Field Values
Method Detail

containsKey

boolean containsKey(java.lang.Object key)
Returns whether the specified key is stored.


get

java.lang.Object get(java.lang.Object key)
Returns the object of the specified key, or null if not found.


put

java.lang.Object put(java.lang.Object key,
                     java.lang.Object value)
Stores an object to the cache.

Returns:
the previous value of the same, or null if no such value

remove

java.lang.Object remove(java.lang.Object key)
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:
getMaxSize()

setLifetime

void setLifetime(int lifetime)
Sets the minimal lifetime. Default: DEFAULT_LIFETIME.

Parameters:
lifetime - the lifetime, unit=milliseconds; if non-posive, they will be removed immediately.
See Also:
getLifetime()

getMaxSize

int getMaxSize()
Returns the maximal allowed size. Defalut: DEFAULT_MAX_SIZE. An mapping won't be removed by GC unless the minimal lifetime or the maximal allowed size exceeds.

See Also:
getLifetime()

setMaxSize

void setMaxSize(int maxsize)
Sets the maximal allowed size.

See Also:
getMaxSize()


Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo