com.ch.odi.common
Class Cache

java.lang.Object
  |
  +--com.ch.odi.common.Cache

public class Cache
extends Object

Description: This is an expiring cache. It is backed by a Hashtable. Objects are not removed idely but only when you try to access them. Copyright: Copyright (c) 2002 Ortwin Glück


Field Summary
static int TTL_1DAY
           
static int TTL_1HOUR
           
static int TTL_1MIN
           
static int TTL_1WEEK
           
static int TTL_5MIN
           
static int TTL_5SEC
           
 
Method Summary
static Cache getInstance()
          Returns the Cache instance.
 Object retrieve(String name)
          Gets an object from the cache by its name The object is referenced by its name specified when it was stored.
 void store(String name, Object obj, int secondsToLive)
          Puts an object into the cache The object obj is put into the cache under the specified unique name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TTL_5SEC

public static final int TTL_5SEC

TTL_1MIN

public static final int TTL_1MIN

TTL_5MIN

public static final int TTL_5MIN

TTL_1HOUR

public static final int TTL_1HOUR

TTL_1DAY

public static final int TTL_1DAY

TTL_1WEEK

public static final int TTL_1WEEK
Method Detail

getInstance

public static Cache getInstance()
Returns the Cache instance. There is only one Cache per application (Singleton).

store

public void store(String name,
                  Object obj,
                  int secondsToLive)
Puts an object into the cache The object obj is put into the cache under the specified unique name. The object expires after secondsToLive specified. Use the TTL-constants. The object is not removed automatically after its time to live ends. It is only removed when you try to retrieve it.
Parameters:
name - The unique key for the object. You need this key to retrieve the object again.
obj - The object to cache
secondsToLive - Time in seconds after that the object expires from the cache.

retrieve

public Object retrieve(String name)
Gets an object from the cache by its name The object is referenced by its name specified when it was stored. When the object was not found or has reached its expiry date it is removed from the cache and null is returned.
Parameters:
name - The key of the object to retrieve