UNPKG

cache-conf

Version:

Simple cache config handling for your app or module

97 lines (52 loc) 1.92 kB
# cache-conf [![Build Status](https://travis-ci.org/SamVerschueren/cache-conf.svg?branch=master)](https://travis-ci.org/SamVerschueren/cache-conf) > Simple cache config handling for your app or module If you don't need caching, you should use [conf](https://github.com/sindresorhus/conf) instead. This module extends that module and abstracts away the caching mechanism. ## Install ``` $ npm install --save cache-conf ``` ## Usage ```js const delay = require('delay'); const CacheConf = require('cache-conf'); const config = new CacheConf(); config.set('unicorn', '🦄', {maxAge: 5000}); console.log(config.get('unicorn')); //=> '🦄' // Wait 5 seconds await delay(5000); console.log(config.get('unicorn')); //=> undefined ``` ## API ### CacheConf([options]) Returns a new instance. #### options Any of the [conf options](https://github.com/sindresorhus/conf#options). ### Instance An extended [conf](https://github.com/sindresorhus/conf#instance) instance. #### get(key, [options]) Get an item. ##### options ###### ignoreMaxAge Type: `boolean`<br> Default: `false` Get the item for the `key` provided without taking the `maxAge` of the item into account. #### set(key, value, [options]) Set an item. #### set(object, [options]) Set multiple items at once. ##### options ###### maxAge Type: `number` Number of milliseconds the cached value is valid. ###### version Type: `string` Version number of the data. If the version provided is not the same as the version of the cached data, the data will be invalid. #### isExpired(key) Boolean indicating if the cached data is expired. ## Related - [conf](https://github.com/sindresorhus/conf) - Simple config handling for your app or module - [observable-conf](https://github.com/SamVerschueren/observable-conf) - Listen for changes in your conf config ## License MIT © [Sam Verschueren](https://github.com/SamVerschueren)