Interface: ICache

H.util.ICache

This interface provides a definition for a generic cache. A cache can store any data elements. To facilitate retrieval of these data elements, each has an identifier an a content size attribute.

Methods

add (id, data, size)boolean

This method adds an element to the cache.

Name Type Description
id *

The identifier of this data element, the value is converted to a string.

data *

the actual data to be stored

size number

The size of the data element

Throws:

Throws an error if the 'size' argument is not a positive number.

Type
Error
Returns:
Type Description
boolean A Boolean value indicating whether the data was successfully added (true)

deRegisterOnDrop (callback)

This method de-registers a callback that is called each time an entry is dropped from the cache.

Name Type Description
callback function

The callback that is invoked for each removed entry

drop (id)

This method explicitly removes an element from the cache.

Name Type Description
id *

the id of the item to drop

forEach (callback, opt_ctx, opt_matcher)

This method executes a callback function on each entry in the cache. If the optional match predicate is specified, the callback is executed only on those entries for which the predicate returns true.

Name Type Description
callback function(string, ?, number)

The callback to be invoked for each entry

opt_ctx Object optional

An optional context object to be used as this within the callback

opt_matcher function optional

An optional match predicate to filter the entries on which the callback operates

get (id, opt_noUpdate)*

This method retrieves an element from the cache.

Name Type Description
id string

The ID of the data element to be retrieved.

opt_noUpdate boolean optional

An optional flag to indicate if the retrieved object should not be marked as 'most recently used' (true)

Returns:
Type Description
* The data corresponding to the ID or undefined if the data element is not in the cache

registerOnDrop (callback)

This method registers a callback to be called each time an entry is dropped from the cache.

Name Type Description
callback function

The callback to be invoked for each removed entry

removeAll (opt_matcher)

This method removes all data elements from the cache. The caller can provide an optional match predicate to narrow down the selection of data elements to be removed.

Name Type Description
opt_matcher function optional

An optional function that receives data entry IDs, data and sizes and returns true or false to remove or leave an entry in the cache, respectively