LRUCache< ID_TYPE, ITEM_TYPE > Class Reference

Collaboration diagram for LRUCache< ID_TYPE, ITEM_TYPE >:

Collaboration graph
[legend]

List of all members.

Classes

class  CacheEntry< ITEM_TYPE >

Public Member Functions

void clear ()
long count ()
ITEM_TYPE get (ID_TYPE aId)
long getCeilingSize ()
int getMaximumItems ()
long getMaximumSize ()
long getSize ()
boolean has (ID_TYPE aId)
Set< ID_TYPE > keys ()
 LRUCache (final int maximumItems, final long maximumSize, final long ceilingSize)
void put (ID_TYPE aId, ITEM_TYPE aItem, long item_size)
void remove (ID_TYPE key)

Private Attributes

long ceilingSize
final Map< ID_TYPE, CacheEntry
< ITEM_TYPE > > 
items
int maximumItems
final long maximumSize
long size = 0

Static Private Attributes

static final int INITIAL_TABLE_SIZE = 2048


Detailed Description

Simple non-thread-safe LRU hash map cache. Thread safety is expected to be provided by the caller.

Constructor & Destructor Documentation

LRUCache ( final int  maximumItems,
final long  maximumSize,
final long  ceilingSize 
)

Caches are created as empty, and populated through use.

Parameters:
maximumItems maximum number of items allowed in the cache
maximumSize maximum size in bytes of the cache
ceilingSize number of bytes to attempt to leave as ceiling room

Creates a linked hash map which expels old elements on declared criterion


Member Function Documentation

void clear (  ) 

Start from beginning, and remove all items from the cache; if cache is disabled, do nothing.

Forces a re-population of all items into the cache.

long count (  ) 

Returns:
the number of entries in the cache

ITEM_TYPE get ( ID_TYPE  aId  ) 

Retrieve an existing item from the cache.

Parameters:
aId is non-null, and corresponds to an existing item in the cache.
Returns:
a non-null Object
Exceptions:
IllegalArgumentException if aId is null, or if the item is not in the cache
IllegalStateException if the item in the cache is null or the cache is disabled

long getCeilingSize (  ) 

Returns:
the reserved headroom/ceiling size (in bytes)

int getMaximumItems (  ) 

Returns:
the maximum number of items in the cache

long getMaximumSize (  ) 

Returns:
the maximum capacity (in bytes) of the cache

long getSize (  ) 

Returns:
the size (in bytes) of all entries in the cache.

boolean has ( ID_TYPE  aId  ) 

Return true only if the corresponding item is in the cache, and has been in it for no more that fRefreshInterval milliseconds; if caching is disabled, then always return false.

Parameters:
aId is non-null.
Returns:
if the corresponding item is in the cache
Exceptions:
IllegalArgumentException if a param does not comply.

Set<ID_TYPE> keys (  ) 

Returns:
the set of all keys in the cache

void put ( ID_TYPE  aId,
ITEM_TYPE  aItem,
long  item_size 
)

If the item is already present, then replace it; otherwise, add it.

If the cache is disabled, do nothing.

Parameters:
aId is non-null
aItem is non-null
item_size is the size of aItem in bytes
Exceptions:
IllegalArgumentException if param does not comply

void remove ( ID_TYPE  key  ) 

Remove an entry from the cache

Parameters:
key the key for the entry


Member Data Documentation

long ceilingSize [private]

final int INITIAL_TABLE_SIZE = 2048 [static, private]

final Map<ID_TYPE, CacheEntry<ITEM_TYPE> > items [private]

Map containing the actual storage

int maximumItems [private]

final long maximumSize [private]

long size = 0 [private]


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:42:31 2012 for Project Wonder by  doxygen 1.5.8