tronicache

1.0.3 • Public • Published

Tronicache

forthebadge

An argument-aware opinionated memcache

Installation

npm install --save tronicache

Usage

Create a cached service

Indefinite caching by default

const { cached } = require('tronicache');
 
const service = cached({
  getUser(uid) {
    // cached indefinitely
  }
})

Configurable timeout

const { cached } = require('tronicache');
 
const service = cached({
  timeout: 2 * 60 * 6000, // all methods at the root are cached for 2 minutes
 
  getUser(uid) {
    // cached for 2 minutes
  }
})

Nested namespace support

const { cached } = require('tronicache');
 
const service = cached({
  users: {
    getUser(uid) {
      // cached indefinitely
    },
 
    posts: {
      // all methods within 'posts' will be cached for 2 minutes
      timeout: 2 * 60 * 1000,
      postsOfUser(uid) {
        const user = this.users.getUser(uid); // notice the scope
        // ...
      }
    }
  },
  notifications: {
    // nothing under 'notifications' is cached
    cache: false,
    fetch() {
      // ...
    },
 
    archive: {
      cache: true, // override in the subnamespace
      fetch() { }
    }
  }
});
 

Package Sidebar

Install

npm i tronicache

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

8.13 kB

Total Files

6

Last publish

Collaborators

  • patrixr