Module cache

Generic LRU cache implementation, used for both query and entity caches within a Store instance.

Functions

Class Cache

Instance Methods


Cache (size)

Creates a new Cache instance

Parameters

Number size Optional cache size, defaults to 1000

Returns

A newly created Cache instance

Cache.prototype.clear ()

Empties the cache

Returns

undefined

Cache.prototype.containsKey (key)

Returns true if the cache contains the given key

Parameters

Object key The cache key

Returns

Boolean True if the cache contains the given key, false otherwise

Cache.prototype.get (key)

Returns the cached value for the given key

Parameters

Object key The cache key

Returns

The cached value

Cache.prototype.isEmpty ()

Returns true if the cache is empty

Returns

Boolean True if the cache is empty, false otherwise

Cache.prototype.put (key, value)

Adds the value with the given key into the cache

Parameters

Object key The cache key
Object value The value

Cache.prototype.remove (key)

Removes the cached value for the given key

Parameters

Object key The cache key

Cache.prototype.size ()

Returns the number of objects in the cache

Returns

Number The number of objects in the cache

createCacheKey (typeOrKey, id)

Creates a cache key

Parameters

String typeOrKey Either an entity key, or a type string
Number id The ID of the entity

Returns

String The cache key