solar.module.cache
Class BaseCache

java.lang.Object
  |
  +--java.util.TimerTask
        |
        +--solar.module.cache.BaseCache
All Implemented Interfaces:
Cache, CacheConstants, java.lang.Runnable
Direct Known Subclasses:
RefreshableCache

public class BaseCache
extends java.util.TimerTask
implements Cache, CacheConstants

A base implementation of cache interface. Once an object is cached, it cannot be refreshed which means it will be stale at pre-determined expiration time.

Version:
$Id: BaseCache.java,v 1.1 2003/10/04 01:49:26 glchen Exp $
Author:
Guanling Chen

Nested Class Summary
 
Nested classes inherited from class solar.module.cache.Cache
Cache.CacheListener
 
Field Summary
protected  java.util.Hashtable _cache
           
protected  int _capacity
           
protected  java.util.List _listeners
           
protected  int _size
           
protected  long _ttl
           
 
Fields inherited from class java.util.TimerTask
 
Fields inherited from interface solar.module.cache.CacheConstants
CACHE_CAPACITY_DEFAULT, CACHE_CAPACITY_INFINIT, CACHE_TTL_DEFAULT, CACHE_TTL_FOREVER
 
Constructor Summary
BaseCache()
           
BaseCache(int capacity, long ttl)
           
 
Method Summary
 void addListener(Cache.CacheListener lis)
          Add a listener to the cache.
 void addObject(java.lang.Object objectId, java.lang.Object obj)
          If the objectId already exists in the cache, this add operation does override the previous cached object with the one supplied in parameter.
 void flush()
          Flush all the objects in the cache.
 CachedObject getCachedObject(java.lang.Object objectId)
          Get the container for an object from the cache.
 java.util.List getCachedObjects()
          Get the list of the cached objects from the cache.
 int getCapacity()
          Get the capacity of the cache.
 java.lang.Object getObject(java.lang.Object objectId)
          Get an object from the cache.
 java.util.List getObjectIds()
          Get the list of the object ids from the cache.
 java.util.List getObjects()
          Get the list of the objects from the cache.
 int getSize()
          Get the number of objects in the cache.
private  void notifyObjectExpired(CachedObject co)
           
 void removeListener(Cache.CacheListener lis)
          Remove a listener from the cache.
 void removeObject(java.lang.Object objectId)
          Remove an object from a cache.
 void run()
           
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_capacity

protected int _capacity

_ttl

protected long _ttl

_size

protected int _size

_listeners

protected java.util.List _listeners

_cache

protected java.util.Hashtable _cache
Constructor Detail

BaseCache

public BaseCache()

BaseCache

public BaseCache(int capacity,
                 long ttl)
Method Detail

addListener

public void addListener(Cache.CacheListener lis)
Description copied from interface: Cache
Add a listener to the cache.

Specified by:
addListener in interface Cache

removeListener

public void removeListener(Cache.CacheListener lis)
Description copied from interface: Cache
Remove a listener from the cache.

Specified by:
removeListener in interface Cache

addObject

public void addObject(java.lang.Object objectId,
                      java.lang.Object obj)
               throws CacheException
If the objectId already exists in the cache, this add operation does override the previous cached object with the one supplied in parameter. But the object is not refreshed meaning expiration time will not be changed.

Specified by:
addObject in interface Cache
CacheException

getObject

public java.lang.Object getObject(java.lang.Object objectId)
Description copied from interface: Cache
Get an object from the cache.

Specified by:
getObject in interface Cache

getCachedObject

public CachedObject getCachedObject(java.lang.Object objectId)
Description copied from interface: Cache
Get the container for an object from the cache.

Specified by:
getCachedObject in interface Cache

getObjects

public java.util.List getObjects()
Description copied from interface: Cache
Get the list of the objects from the cache.

Specified by:
getObjects in interface Cache

getCachedObjects

public java.util.List getCachedObjects()
Description copied from interface: Cache
Get the list of the cached objects from the cache.

Specified by:
getCachedObjects in interface Cache

getObjectIds

public java.util.List getObjectIds()
Description copied from interface: Cache
Get the list of the object ids from the cache.

Specified by:
getObjectIds in interface Cache

removeObject

public void removeObject(java.lang.Object objectId)
Description copied from interface: Cache
Remove an object from a cache.

Specified by:
removeObject in interface Cache

getCapacity

public int getCapacity()
Description copied from interface: Cache
Get the capacity of the cache.

Specified by:
getCapacity in interface Cache

getSize

public int getSize()
Description copied from interface: Cache
Get the number of objects in the cache.

Specified by:
getSize in interface Cache

flush

public void flush()
Description copied from interface: Cache
Flush all the objects in the cache.

Specified by:
flush in interface Cache

run

public void run()
Specified by:
run in interface java.lang.Runnable
Specified by:
run in class java.util.TimerTask

notifyObjectExpired

private void notifyObjectExpired(CachedObject co)