0.3.1 • Published 7 years ago

vig-cache v0.3.1

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

Build Status Coverage Status

KVCache

Key-value based Cache taking url, params, query and session info into account.

Very simple to use. JSON is recommanded, but String can be saved too.

Improvement

Before:

Requests per second:    12.98 [#/sec] (mean)

After:

Requests per second:    307.32 [#/sec] (mean)

Usage

// for ts
import { KVCache } from "vig-cache";
import * as redis from "redis";

or

// for js
const KVCache = require('vig-cache').KVCache;
const Redis = require("redis");

then

let config = {
  host: '127.0.0.1',
  port: 6379,
  db: 0
};
let redis = Redis.createClient(config);

const cache = new KVCache(redis);

// JSON storage
await cache.setJSON(req, user, {value: 100});
await cache.getJSON(req, user);

// String storage

await cache.set(req, user, 'string');
let saved = await KVCache.get(req, user');
await cache.clear(req);   // For Both JSON and String

// with Expressjs

cache.attach(app)

app.get('/', async function(req, res) {
  if (req.cache.data) {
     return res.send(req.cache.data.text)
  }
 await req.cache.setJSON(req, user, {text: 'toBeCached'});
 res.send('toBeCached');
});

Setting travis and coveralls badges

  1. Sign in to travis and activate the build for your project.
  2. Sign in to coveralls and activate the build for your project.
  3. Replace calidion/vig-cache with your repo details like: "ospatil/generator-node-typescript".
0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago