cache

api. cache

Source:
Properties:
Name Type Description
redisPrefix string

The prefix for all redis keys (from api.config.general.cachePrefix).

lockPrefix string

The prefix for all redis locks (from api.config.general.lockPrefix).

lockDuration Number

The default time a key will be locked for (from api.config.general.lockDuration).

lockName string

The name of the lock for this ActionHero instance (from api.id).

lockRetry Number

How long to wait before trying to get a lock again (100ms).

Redis cache connectivity and support methods.

Extends

Methods

(async, static) clear() → {Promise.<Boolean>}

Source:

Removes all keys in redis which are under this ActionHero namespace. Potentially very slow.

Returns:

will return true if successful.

Type
Promise.<Boolean>

(async, static) destroy(key) → {Promise.<Boolean>}

Source:
See:

Delete an item in the cache. Will throw an error if the item named by key is locked.

Parameters:
Name Type Description
key string

The name of the item to destroy in the cache.

Returns:

returns true if the item was deleted, false if it was not (or not found).

Type
Promise.<Boolean>

(async, static) dumpRead(file) → {Promise.<Number>}

Source:
See:

Load in contents for redis (and api.cache) saved to a file Warning! Any existing keys in redis (under this ActionHero namespace) will be removed.

Parameters:
Name Type Description
file string

The file to load into the cache.

Returns:

The number of keys loaded into redis.

Type
Promise.<Number>

(async, static) dumpWrite(file) → {Promise.<Number>}

Source:
See:

Write the current concents of redis (only the keys in ActionHero's namespace) to a file.

Parameters:
Name Type Description
file string

The file to save the cache to.

Returns:

The number of keys saved to disk.

Type
Promise.<Number>

(async, static) keys() → {Promise.<Array>}

Source:

Returns all the keys in redis which are under this ActionHero namespace. Potentially very slow.

Returns:

Promise resolves an Array of keys

Type
Promise.<Array>

(async, static) listLength(key) → {Promise.<Number>}

Source:

Check how many items are stored in a shared queue/list in redis.

Parameters:
Name Type Description
key string

The name of the object to save.

Returns:

The length of the list in redis. 0 will re returned for non-existant lists.

Type
Promise.<Number>

(async, static) load(key, options) → {Promise.<Object>}

Source:
See:

Load an item from the cache. Will throw an error if the item named by key cannot be found.

Parameters:
Name Type Description
key string

The name of the item to load from the cache.

options Object

Options is an object with the propety expireTimeMS. This can be used to re-set an expiry time on the cached object after reading it.

Returns:

Returns an object with {key, value, expireTimestamp, createdAt, lastReadAt}

Type
Promise.<Object>

(async, static) lock(key, expireTimeMS) → {Promise.<Boolean>}

Source:
See:

Lock an item in redis (can be a list or a saved item) to this ActionHero process.

Parameters:
Name Type Description
key string

The name of the object to lock.

expireTimeMS string

How long to lock this item for.

Returns:

Returns true or false, depending on if the item was locked successfully.

Type
Promise.<Boolean>

(async, static) locks() → {Promise.<Array>}

Source:

Returns all the locks in redis which are under this ActionHero namespace. Potentially slow.

Returns:

Promise resolves an Array of keys

Type
Promise.<Array>

(async, static) pop(key) → {Promise.<Object>}

Source:
See:

Pop (get) an item to a shared queue/list in redis.

Parameters:
Name Type Description
key string

The name of the shared queue/list.

Returns:

The item The object which was saved. It can also be a Number, String, or Array.

Type
Promise.<Object>

(async, static) push(key, item) → {Promise.<Boolean>}

Source:
See:

Push an item to a shared queue/list in redis.

Parameters:
Name Type Description
key string

Name of the shared queue/list.

item Object

The item The object to save. It can also be a Number, String, or Array.

Returns:

Returns true if the object was pushed.

Type
Promise.<Boolean>

(async, static) save(key, value, expireTimeMS) → {Promise.<Boolean>}

Source:
See:

Save an item in the cache. If an item is already in the cache with the same key, it will be overritten. Throws an error if the object is already in the cache and is locked.

Parameters:
Name Type Description
key string

The name of the object to save.

value Object

The object to save. It can also be a Number, String, or Array.

expireTimeMS Number

(optional) Should the saved item expire after expireTimeMS?

Returns:

Returns true if the object was saved.

Type
Promise.<Boolean>

(async, static) size() → {Promise.<Number>}

Source:

Returns the number of keys in redis which are under this ActionHero namespace. Potentially very slow.

Returns:

Promise reslves in interger (length)

Type
Promise.<Number>

(async, static) unlock(key) → {Promise.<Boolean>}

Source:
See:

Unlock an item in redis (can be a list or a saved item) which was previously locked by this ActionHero process.

Parameters:
Name Type Description
key string

The name of the object to unlock.

Returns:

Returns true or false, depending on if the item was unlocked successfully.

Type
Promise.<Boolean>