Joshua
open source statistical hierarchical phrase-based machine translation system
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
joshua.util.Cache< K, V > Class Reference
Inheritance diagram for joshua.util.Cache< K, V >:
[legend]
Collaboration diagram for joshua.util.Cache< K, V >:
[legend]

List of all members.

Public Member Functions

 Cache (int maxCapacity)
 Cache ()
get (Object key)
put (K key, V value)
boolean containsKey (Object key)

Static Public Attributes

static final int DEFAULT_CAPACITY = 100000000
static final int INITIAL_CAPACITY = 1000000
static final float LOAD_FACTOR = 0.75f
static final boolean ACCESS_ORDER = true

Protected Member Functions

boolean removeEldestEntry (Map.Entry< K, V > eldest)

Package Attributes

int maxCapacity

Static Private Attributes

static final long serialVersionUID = 6073387072740892061L
static Logger logger = Logger.getLogger(Cache.class.getName())

Detailed Description

Cache is a class that implements a least recently used cache. It is a straightforward extension of java.util.LinkedHashMap with its removeEldestEntry method overridden, so that stale entries are deleted once we reach the specified capacity of the Cache.

This class is quite useful for storing the results of computations that we would do many times over in the FeatureFunctions.

Author:
Chris Callison-Burch
Since:
14 April 2005

Constructor & Destructor Documentation

joshua.util.Cache< K, V >.Cache ( int  maxCapacity)

Creates a Cache with a set capacity.

Parameters:
maxCapacitythe maximum capacity of the cache.
joshua.util.Cache< K, V >.Cache ( )

Creates a Cache with the DEFAULT_CAPACITY.


Member Function Documentation

boolean joshua.util.Cache< K, V >.containsKey ( Object  key)
V joshua.util.Cache< K, V >.get ( Object  key)
V joshua.util.Cache< K, V >.put ( key,
value 
)
boolean joshua.util.Cache< K, V >.removeEldestEntry ( Map.Entry< K, V >  eldest) [protected]

This method is invoked by put and putAll after inserting a new entry into the map. Once we reach the capacity of the cache, we remove the oldest entry each time a new entry is added. This reduces memory consumption by deleting stale entries.

Parameters:
eldestthe eldest entry
Returns:
true if the capacity is greater than the maximum capacity

Member Data Documentation

final boolean joshua.util.Cache< K, V >.ACCESS_ORDER = true [static]

By default, ordering mode of the cache is access order (true).

final int joshua.util.Cache< K, V >.DEFAULT_CAPACITY = 100000000 [static]

A constant is used as the default the cache size if none is specified.

final int joshua.util.Cache< K, V >.INITIAL_CAPACITY = 1000000 [static]

Default initial capacity of the cache.

final float joshua.util.Cache< K, V >.LOAD_FACTOR = 0.75f [static]

Default load factor of the cache.

Logger joshua.util.Cache< K, V >.logger = Logger.getLogger(Cache.class.getName()) [static, private]

Logger for this class.

int joshua.util.Cache< K, V >.maxCapacity [package]

Maximum number of items that the cache can contain.

final long joshua.util.Cache< K, V >.serialVersionUID = 6073387072740892061L [static, private]