com.anthonyeden.lib.cache
Class InMemoryCache

java.lang.Object
  extended bycom.anthonyeden.lib.cache.AbstractCache
      extended bycom.anthonyeden.lib.cache.InMemoryCache
All Implemented Interfaces:
Cache

public class InMemoryCache
extends AbstractCache

Cache implementation which stores the cached values in memory.

Since:
1.1
Author:
Anthony Eden

Field Summary
 
Fields inherited from class com.anthonyeden.lib.cache.AbstractCache
DEFAULT_TTL, ttl
 
Constructor Summary
InMemoryCache()
          Construct a new InMemoryCache.
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Get the value for the given key from the cache.
 void loadConfiguration(Configuration configuration)
          Load the Cache's configuration from the given Configuration object.
 void put(java.lang.Object key, java.lang.Object value)
          Insert a value into the cache.
 void put(java.lang.Object key, java.lang.Object value, int ttl)
          Insert a value into the cache with the specified time to live.
 void remove(java.lang.Object key)
          Remove a value from the cache.
 
Methods inherited from class com.anthonyeden.lib.cache.AbstractCache
getTTL, isExpired, setTTL, setTTL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemoryCache

public InMemoryCache()
Construct a new InMemoryCache.

Method Detail

get

public java.lang.Object get(java.lang.Object key)
Get the value for the given key from the cache. This method may return null if there is no value or the value is expired.

Parameters:
key - The key
Returns:
The value or null

put

public void put(java.lang.Object key,
                java.lang.Object value)
Insert a value into the cache.

Parameters:
key - The key
value - The value

put

public void put(java.lang.Object key,
                java.lang.Object value,
                int ttl)
Insert a value into the cache with the specified time to live. The specified time to live overrides the default time to live. A value less than 0 is be considered as "infinate".

Parameters:
key - The key
value - The value
ttl - The time to live

remove

public void remove(java.lang.Object key)
Remove a value from the cache.

Parameters:
key - The key

loadConfiguration

public void loadConfiguration(Configuration configuration)
                       throws ConfigurationException
Load the Cache's configuration from the given Configuration object.

Specified by:
loadConfiguration in interface Cache
Overrides:
loadConfiguration in class AbstractCache
Parameters:
configuration - The Configuration object
Throws:
ConfigurationException


Copyright (c) 2000-2003 Anthony Eden. All Rights Reserved.