polycache
v0.0.10
Published
Library for cache multi drivers.
Downloads
1
Readme
PolyCache
Library for cache multi drivers.
Install
npm install polycache
Usage
PolyCache = require "polycache"
# PolyCache uses memory driver by default
# and if configuration exists, uses each driver
cache = new PolyCache
# use memory driver
cache.set("largeCsv:2014-06-01:2014-06-14", bigValue) # to memory
.then(->
cache.get("largeCsv:2014-06-01:2014-06-14") # from memory
)
.then(->
cahce.close()
)
Driver Rules
Use memory for the keys frequently used and the values that size are small, use redis or memcached for the keys used for multi hosts and use file for large value size.
PolyCache = require "polycache"
cache = new PolyCache
file:
dir: "/tmp"
redis:
host: "localhost"
port: 6379
cache.addRule PolyCache.File, {key: /largeCsv/}
cache.addRule PolyCache.File, {val: {gt: 1024 * 1024}}
cache.addRule PolyCache.Redis, {key: "sharedSetting"}
# and if any rules do not match, use memory driver
cache.set("largeCsv:2014-06-01:2014-06-14", bigValue) # to file
.then(->
cache.get("largeCsv:2014-06-01:2014-06-14") # from file
)
.then(->
cahce.close()
)
no cache mode
if you do not use cache in development, so you can give app via env NO_CACHE=true.
$ NO_CACHE=true node app.js // it includes poly cache
or give configure:
new PolyCache({noCache: true})
Author
Muddy Dixon [email protected]
License
Apache License Version 2.0