npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dynamis

v0.3.0

Published

Node.JS cache API for various persistence layers

Downloads

14

Readme

Dynamis

Version npmBuild StatusDependenciesCoverage Status

Node.JS cache API for various persistence layers. Dynamis aims to implement a minimal cache API with maximal reusability. If you don't want to bother with specifics Dynamis is made for you. However, if you like full control and features than you should want to use any persistence layer directly.

Installation and usage

npm install dynamis --save

Dynamis does not depend on the supported persistence layers to keep the amount of dependencies small. You'll have to add your desired persistence layer to t

var Dynamis = require('dynamis');
  , redis = require('redis').createClient();

//
// Initialize cache layer, by providing the connection object and options.
//
var dynamis = new Dynamis('redis', redis, { database: 1 });

Supported

  • Memory: In process memory.
  • Memcached: Memcached
  • Redis: Node-redis
  • CouchDB: Cradle
  • LevelDB: LevelUp

Table of Contents

Any persistence layer will have access to the following methods, newly developed layers should implement all methods below.

API

Internal

Events

Dynamis: get

Get a cached value from the persistence layer.

key: String (required) database key done: Function (required) completion callback

dynamis.get('key', function done(error, value) {
  console.log(value);
});

Dynamis: set

Store key:value data in the persistence layer, with an optional time to live.

key: String (required) database key value: String (required) value to JSON.stringify ttl: Number (optional) time to live in seconds, defaults to 0 (never) done: Function (required) completion callback

var value = { valid: 'json' };
dynamis.set('key', value, function done(error, result) {
  console.log(result);
});

Dynamis: expire

Set or refresh a time to live on the key.

key: String (required) database key ttl: Number (required) time to live in seconds done: Function (required) completion callback

dynamis.expire('key', 10, function done(error, result) {
  console.log(result);
});

Dynamis: del

Delete the key and value from the persistence layer

key: String (required) database key done: Function (required) completion callback

dynamis.del('key', function done(error, result) {
  console.log(result);
});

Dynamis: flush

Flush all data that is in the persistence layer. This feature is also available by setting a environment variable, per example CACHE=flush:redis would flush all data from the redis database by adding flush as before hook.

done: Function (required) completion callback

dynamis.flush(function done(error, result) {
  console.log(result);
});

Dynamis.execute

All API calls will flow through this function. Execute will emit before so that any registered functions will be executed. before will only be run once, thereafter any provided function will executed immediately.

context: Object (required) usually the persistence layer fn: Function (required) persistence layer method to call on context arguments: Mixed (optional) additional arguments to supply to the function

dynamis.execute(redis.database, redis.database.set, key, value, done)

Dynamis.before

Loops over a set of API functions defined in dynamis.pre. Before will be executed once, as soon as any API method is called, per example dynamis.create in cradle.

context: Object (required) usually the persistence layer fn: Function (required) persistence layer method to call on context args: Array (required) arguments to supply to the function

dynamis.before(redis.database, redis.database.set, [ key, value, done ])

Dynamis.on: error

Errors or failures emitted by the persistence layer will be emitted from dynamis. Handling connection or persistence errors from any layer will be done for you. Ignoring these errors is possible, EventEmitter3 will not throw the error when no listener is registered.

var Dynamis = require('dynamis');
  , redis = require('redis').createClient();

//
// Initialize cache layer and listen to emitted errors.
//
var dynamis = new Dynamis('redis', redis, {});
dynamis.on('error', function handleError() {
  console.log(arguments);
});