Class: Cache

Cache

In-Memory LRU Cache. For feature overview see wiki

new Cache(cachespec)

Parameters:
Name Type Description
cachespec Object

See wiki for details

Source:

Members

stats :Object

{'hitCount':{Number}, 'missCount':{Number}, 'reqeustCount':{Number}}

Type:
  • Object
Source:

Methods

get(key, callback)

Get value for key, NOTE: This is ASYNCHRONOUS and result is available from callback function Automatically load the value if not present and an auto loader function is configured. Callback is called with two arguments (error,result) . Error contains any error reported by auto loader, or any error while creating the entry in cache, otherwise its null. Result contains the result from the cache, which in turn may have been received from the autoloader, if the entry had expired or was not present. If no autoloader is configured or the entry was present in cache, the callback is called with the result in cache. In conformance to async laws, the callback is still asynchronous and not called immediately. For synchronous get, see Cache#getSync

Parameters:
Name Type Description
key String
callback function
Source:

getIfPresent(key) → {*}

Get value for key as present in cache, No attempt to load the key will be done even if a loader is configured

Parameters:
Name Type Description
key String
Source:
Returns:

value if present, null otherwise

Type
*

getSync(key) → {*}

Get value for key, NOTE: This is SYNChronous and result is returned by the function itself Automatically load the value if not present and an auto loader function is configured. In this case, we assume that autoloader will also be calling the cache callback synchronously Returns result contains the result from the cache, which in turn may have been received from the autoloader, if the entry had expired or was not present

Parameters:
Name Type Description
key String
Source:
Returns:

Value associated with the key in cache

Type
*

invalidate(key)

Invalidate value associated with the key the given key(and associated value pair) is removed from cache. If a removal listener is configured, it will be invoked with key value pair //and removal cause as 'explicit'

Parameters:
Name Type Description
key
Source:

put(key, value)

Parameters:
Name Type Description
key *

Although using other than String or Number may not be meaningful since underlying object used as backing cache will do a toString() on the key

value *

Null and undefined are not allowed

Source: