Package Exports
- rethinkdb-cache
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 (rethinkdb-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
rethinkdb-cache
RDB warm cache module based upon https://gist.github.com/threepointone/62dd587d42819fc72284
How to use?
- Run tests:
npm install && npm test
- Install it:
npm install --save rethinkdb-cache
NOTE: You can use yarn instead of npm if you like.
- Require it:
const rdbCache = require('rethinkdb-cache'),
rdbSettings = {
host: 'localhost',
port: '28015',
user: 'user',
password: 'password',
db: 'db',
timeout: 60
},
tableName = 'app_cache',
ttl = 24;
/**
* @params {object || arr} rdbSettings (optional)
* @params {string} tableName (optional)
* @params {integer} ttl (optional)
*
*/
const CACHE = new rdbCache(rdbSettings, tableName, ttl);rdbSettings: An object with your usual RethinkDB connection settings, if the DB does not exist, it will be created
tableName: A string with the name of the table you want to use as cache table, if it does not exist, it will be created
ttl: An integer representing the maximum time (in hours) objects should be stored in cache before being completely flushed in order to be fully recreated instead of warmly updated
Usage:
const data = {"name": "foobar"}
if (!CACHE.retrieve("some-key")) {
// Not-in-cache-logic goes here...
CACHE.send("some-key", data);
}
else {
// Return from cache
const myData = JSON.parse(CACHE.retrieve("some-key")).val;
return myData;
}