Openfire 3.5.0 Javadoc

org.jivesoftware.util.cache
Interface Cache<K,V>

All Superinterfaces:
Map<K,V>
All Known Implementing Classes:
CacheWrapper, DefaultCache

public interface Cache<K,V>
extends Map<K,V>

General purpose cache. It stores objects associated with unique keys in memory for fast access. All keys and values added to the cache must implement the Serializable interface. Values may implement the Cacheable interface, which allows the cache to determine object size much more quickly. These restrictions allow a cache to never grow larger than a specified number of bytes and to optionally be distributed over a cluster of servers.

If the cache does grow too large, objects will be removed such that those that are accessed least frequently are removed first. Because expiration happens automatically, the cache makes no gaurantee as to how long an object will remain in cache after it is put in.

Optionally, a maximum lifetime for all objects can be specified. In that case, objects will be deleted from cache after that amount of time, even if they are frequently accessed. This feature is useful if objects put in cache represent data that should be periodically refreshed; for example, information from a database.

All cache operations are thread safe.

See Also:
Cacheable

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 long getCacheHits()
          Returns the number of cache hits.
 long getCacheMisses()
          Returns the number of cache misses.
 int getCacheSize()
          Returns the size of the cache contents in bytes.
 long getMaxCacheSize()
          Returns the maximum size of the cache in bytes.
 long getMaxLifetime()
          Returns the maximum number of milliseconds that any object can live in cache.
 String getName()
          Returns the name of the cache.
 void setMaxCacheSize(int maxSize)
          Sets the maximum size of the cache in bytes.
 void setMaxLifetime(long maxLifetime)
          Sets the maximum number of milliseconds that any object can live in cache.
 void setName(String name)
          Sets the name of the cache
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Method Detail

getName

String getName()
Returns the name of the cache.

Returns:
the name of the cache.

setName

void setName(String name)
Sets the name of the cache

Parameters:
name - the name of the cache

getMaxCacheSize

long getMaxCacheSize()
Returns 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.

Returns:
the maximum size of the cache in bytes.

setMaxCacheSize

void setMaxCacheSize(int maxSize)
Sets 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.

Parameters:
maxSize - the maximum size of the cache in bytes.

getMaxLifetime

long getMaxLifetime()
Returns the maximum number of milliseconds that any object can live in cache. Once the specified number of milliseconds passes, the object will be automatically expried from cache. If the max lifetime is set to -1, then objects never expire.

Returns:
the maximum number of milliseconds before objects are expired.

setMaxLifetime

void setMaxLifetime(long maxLifetime)
Sets the maximum number of milliseconds that any object can live in cache. Once the specified number of milliseconds passes, the object will be automatically expried from cache. If the max lifetime is set to -1, then objects never expire.

Parameters:
maxLifetime - the maximum number of milliseconds before objects are expired.

getCacheSize

int getCacheSize()
Returns 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.

Returns:
the size of the cache contents in bytes.

getCacheHits

long getCacheHits()
Returns 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.

Returns:
the number of cache hits.

getCacheMisses

long getCacheMisses()
Returns 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.

Returns:
the number of cache hits.

Openfire 3.5.0 Javadoc

Copyright © 2003-2007 Jive Software.