SimpleLRUDVOCacher

public class SimpleLRUDVOCacher extends Component implements DVOCacher

The SimpleLRUDVOCacher is the simple DVO cacher which possess LRU, Least-Recently Used features. When there is not enough room to store the DVO as a cache. It tries to remove the oldest record (the one that has not retrieved for longest times). Creation Date: 12/2/2007

Author:Twinsen Tsang

Constructors

SimpleLRUDVOCacher

public SimpleLRUDVOCacher()

Constructor. Use SimpleLRUDVOCacher(int) instead of this constructor. This is reserved for Piazza Common component initialization only.

SimpleLRUDVOCacher

public SimpleLRUDVOCacher(int cacheSize)

Explicit Constructor.

Parameters:
  • cacheSize – The maximum size of the cache.

Methods

activeSize

public int activeSize()

The activs size is defined how many DVO are already stored in the cacher.

Returns:Get the active size of DVO cacher.

efficieny

public double efficieny()

This method is used to calculate the getDVO(String) efficieny (eff) of the cacher. It is formulated :

            cacheHit
eff = (--------------------) * 100
       cacheHit + cacheMiss
Returns:the efficiency of the cacher.

getDVO

public DVO getDVO(String key)

Get the DVO cache from the particular key.

Parameters:
  • key – The key field of the DVO.
Returns:

Return null if the cache record does not exist.

init

protected void init()

Invoked for initialization.

maxSize

public int maxSize()

The maximum size is defined how many DVO are the cacher can store before swapping out happens.

Returns:Get the maximum size of DVO cacher.

putDVO

public void putDVO(String key, DVO cacheItem)

Store the DVO cacheItem into the cacher with the specified Key. If the DVO in the key is already exist, it throws CacheException indicating cache duplication.

Parameters:
  • key – The key field of the DVO.
  • cacheItem – The DVO item to be cached.
Throws:

See also: .putOrUpdateDVO(String,DVO);

putOrUpdateDVO

public void putOrUpdateDVO(String key, DVO cacheItem)

Store or Update the DVO cacheItem into the cacher with the specified Key.

Parameters:
  • key – The key field of the DVO.
  • cacheItem – The DVO item to be cached.

removeAll

public void removeAll()

Remove all the cache record.

removeDVO

public void removeDVO(String key)

Remove the cache record with the key field equal to key.

Parameters:
  • key – The DVO’s key field to remove.