Cache
Classes
- Cache
- InMemoryCache
creates an in memory cache and an interface to interact with it
- RedisCache
maintains a connection with redis and communicates with redis
Functions
- NO_VALUE Returns a string that is usable as an indication that a value was stored into the cache that represents a null value()
- use getNs(key) ⇒
Promise
- use multiGetNs(keys) ⇒
Promise
- especially those that can cause unit tests to hang until everything shuts down cleanly.()
- create Creates a cache of a specifed type(options)
- get gets the value at the key(key)
- multiGet gets and returns that values from multiple keys(keys)
- set sets a value into the cache(key, value, opts)
- remove removes a value from the cache(key)
- clear clears the inmemory cache()
- get gets and returns a value from the cache(key)
- multiGet gets and returns that values from multiple keys(keys)
- set sets a value into the redis cache(key, value, opts)
- remove removes a value from the redis cache(key, opts)
- end ends the connection to the redis database()
Cache
new Cache()
Creates a Cache object
Param | Type | Description |
---|---|---|
options.namespace | string | the namespace string to use in the xxxNs methods. Defaults to 'app' |
InMemoryCache
creates an in memory cache and an interface to interact with it
new InMemoryCache(options)
Param | Type |
---|---|
options | object |
RedisCache
maintains a connection with redis and communicates with redis
new RedisCache(options)
Param | Type | Description |
---|---|---|
options | object | |
options.connection | object | config for the redis connection |
NO_VALUE Returns a string that is usable as an indication that a value was stored into the cache that represents a null value()
create Creates a cache of a specifed type(options)
Kind: global function
Param | Type | Description |
---|---|---|
options | object | the cache options |
options.type | string | the type of cache to make. If unrecognized, this will return a no-op cache. Possible values: 'redis', 'inMemory', none' |
options.prefix | string | a string that will prepended (with a ':') to all keys when accessing the cache. The resulting key will be prefix:key |
options.cacheConfig | object | This can be an object, JSON or reference to a json/js file. If defined, it will be expanded and merged with the other options like prefix. This allows the cache type to be controlled by an environment variable or file. |
get gets the value at the key(key)
Kind: global function
Param | Type | Description |
---|---|---|
key | string | the value to get |
multiGet gets and returns that values from multiple keys(keys)
Kind: global function
Param | Type | Description |
---|---|---|
keys | array | the keys to get the values for |
set sets a value into the cache(key, value, opts)
Kind: global function
Param | Type | Description |
---|---|---|
key | string | the key to set the value at |
value | any | the value to be set |
opts | objct |
remove removes a value from the cache(key)
Kind: global function
Param | Type | Description |
---|---|---|
key | string | the key to remove the value at |
clear clears the inmemory cache()
get gets and returns a value from the cache(key)
Kind: global function
Param | Type | Description |
---|---|---|
key | string | value to get from the cache |
multiGet gets and returns that values from multiple keys(keys)
Kind: global function
Param | Type | Description |
---|---|---|
keys | array | the keys to get the values for |
set sets a value into the redis cache(key, value, opts)
Kind: global function
Param | Type | Description |
---|---|---|
key | string | the key to set the value at |
value | any | the value to be set |
opts | objct |
remove removes a value from the redis cache(key, opts)
Kind: global function
Param | Type | Description |
---|---|---|
key | string | the key to remove the value at |
opts | * |
end ends the connection to the redis database()
Kind: global function