Package Exports
- cache-flex
 
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cache-flex) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Cache flex
An in-memory cache with extra options to fix value types and set constants in cache, for more consistency.
Methods
.set(key, value, options)
- Returns a promise that resolves with the set value.
 keyshould be a string.valuecan be anything except forundefined,nullorNaN.options(object)makeConstant(boolean): if set totrue, does not allow the value to be updated.fixType(boolean): if set totrue, does not allow the type of the value to be changed.ttl(number) (time in milliseconds): if specified, removes the value after the given interval.expiryCallback(value)(function): if provided with validttl, this function gets called right after a value is expired with the value.
- .setSync(...) is the synchronous version with the same parameters, returns the value.
 
.setFixType(key, value)
- fixes the type for the 
valueagainst the givenkey, and can be only updated with avaluewith same type as inital type ofvalue. - Returns a promise that resolves with the set value.
 - .setFixTypeSync(...) is the synchronous version with the same parameters, returns the value.
 
.setConstant(key, value)
- sets the value as a constant i.e. the value cannot be changed later on.
 - Returns a promise that resolves with the set value.
 - .setConstantSync(...) is the synchronous version with the same parameters, returns the value.
 
.get(key)
- Returns a promise that resolves with the value stored against the 
key. - .getSync(...) is the synchronous version with the same parameters, returns the value.
 
.update(key, value)
- Updates existing value against 
keywithvalue. - Returns a promise that resolves with the updated value.
 
.setOrUpdate(key, value)
- Updates or sets value against 
keywithvalue. - Returns a promise that resolves with the updated or set value.
 
Usage
const cache = require('cache-flex');
cache.setSync('someKey', 'someValue')
let value = cache.getSync('someKey');
cache.set('someKey', {a: 'some value'})
  .then(value => {
    // 'value' is {a: 'some value'}
    let result = cache.get('someKey')
      .then(result => {
        // 'value' is {a: 'some value'}
      })
      .catch(err => {
        // handle error with 'get'
      });
  })
  .catch(err => {
    // handle error with 'set'
  });