CacheClient

module:cache. CacheClient

Base class for the cache clients, implements cache protocol in the same class, not supported methods just do nothing without raising any errors

Constructor

new CacheClient(optionsopt)

Source:
Parameters:
Name Type Attributes Description
options object <optional>

Methods

applyOptions(options)

Description:
  • Prepare options to be used safely, parse the reserved params that start with bk- from the url and store in the options

Source:
Parameters:
Name Type Description
options object

applyReservedOptions(options)

Description:
  • Handle reserved options

Source:
Parameters:
Name Type Description
options object

clear(pattern, callbackopt)

Description:
  • Clear all or only matched keys from the cache

Source:
Parameters:
Name Type Attributes Description
pattern string
callback function <optional>

close()

Description:
  • Close current connection, ports.... not valid after this call

Source:

del(key, options, callbackopt)

Description:
  • Delete an item from the cache

Source:
Parameters:
Name Type Attributes Description
key string
options object
callback function <optional>

get(key, options, callback)

Description:
  • Returns an item from the cache by a key, callback is required and it acceptes only the item, on any error null or undefined will be returned

Source:
Parameters:
Name Type Description
key string
options object
callback function

incr(key, val, options, callbackopt)

Description:
  • Add/substract a number from the an item, returns new number in the callback if provided, in case of an error null/indefined should be returned

Source:
Parameters:
Name Type Attributes Description
key string
val number
options object
callback function <optional>

limiter(key, val, options, callbackopt)

Description:
  • Rate limit check, by default it uses the server LRU cache meaning it works within one physical machine only.

Source:
Parameters:
Name Type Attributes Description
key string
val number
options object

same as for module:metrics.TokenBucket rate limiter

Properties
Name Type Attributes Description
name string

unique id, can be IP address, account id, etc...

rate int

rate per interval

interval int

in milliseconds

max int <optional>
callback function <optional>

arguments must be:

  • 1st arg is a delay to wait till the bucket is ready again,
  • 2nd arg is an object with the bucket state: { delay:, count:, total:, elapsed: }

lock(name, options, callbackopt)

Description:
  • Lock by name by default return an error

Source:
Parameters:
Name Type Attributes Description
name string
options object
callback function <optional>

put(key, val, options, callbackopt)

Description:
  • Store an item in the cache

Source:
Parameters:
Name Type Attributes Description
key string
val string
options object
Properties
Name Type Attributes Description
ttl int <optional>

TTL in milliseconds

callback function <optional>

stats(optionsopt, callbackopt)

Description:
  • Returns the cache statistics to the callback as the forst argument, the object tructure is specific to each implementstion

Source:
Parameters:
Name Type Attributes Description
options object <optional>
callback function <optional>

unlock(name, options, callbackopt)

Description:
  • Unlock by name

Source:
Parameters:
Name Type Attributes Description
name string
options object
callback function <optional>