rethinkdb-cache

0.4.6 • Public • Published

rethinkdb-cache

Build Status

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;
      }

Package Sidebar

Install

npm i rethinkdb-cache

Weekly Downloads

1

Version

0.4.6

License

LGPL-3.0

Last publish

Collaborators

  • carlosreza
  • jmlevick