Skip to content

diamondio/magnemite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magnemite - Easy redis-backed caching

Getting Started

You will need to have the following resources available in your infrastucture:

  • Redis
  • Node.js

Install magnemite by doing

npm install --save magnemite

Using Magnemite

var magnemite = require('magnemite');

var cache = new magnemite({url: 'redis://localhost:6379'});

cache.register('user', function (dbname, cb) {
  // This function goes off and grabs the "user" object from wherever the "true" source is
  setImmedate(function () {
    cb(null, {
      userId: dbname,
      name: 'Jake'
    })
  });
});

cache.get('user', '1234', function (err, user) {
  console.log('Got the user object:', user);
  cache.invalidate('user', '1234', function (err) {
    console.log('Invalidated the 1234 user');
    cache.invalidate('user', function (err) {
      console.log('Invalidated the every user');
      cache.invalidate(function (err) {
        console.log('Invalidated the whole cache');
      });
    });
  });
});

Releases

No releases published

Packages

No packages published