Coder Social home page Coder Social logo

expeditious-engine-memory's Introduction

expeditious-engine-memory

Circle CI

An in memory engine for expeditious. Cache entries are - you guessed it - stored in the node.js process memory. This cache engine will lose everything stored if your process restarts, and could lead to memory bloat and slow garbage collections if you're not careful with the size and volume of entries!

Usage

You can use this module standalone or with expeditious which is the recommended approach since it simplifies interactions and allows you to easily switch cache engines.

var expeditious = require('expeditious');

var countries = expeditious({
  // Use the expeditious memory engine
  engine: require('expeditious-engine-memory')(),
  // Prefix all entries with 'countries'
  namespace: 'countries',
  // Auto parse json entries
  objectMode: true,
  // 1 hour timeout for entries
  defaultTtl: (60 * 1000 * 60),
});

countries.set({
  key: 'ireland',
  value: {
    population: '4.595 million',
    capital: 'Dublin'
  }
}, function (err) {
  if (!err) {
    console.error('failed to add "ireland" to the cache');
  } else {
    console.log('add "ireland" to the cache');
  }
});

API

Each API function takes a callback function as the last parameter and it receives up to two arguments as per node.js convention, error err and an optional result, res.

set(key, value, expire, callback)

Set a key (String) in the cache with a given (String) value. expire must be a Number greater than 0.

get(key, callback)

Get a specific item from the cache. Returns null if the entry is not found.

del(key, callback)

Delete a specific item from the cache. Callback receives only an error parameter.

keys(callback)

List all keys that this engine instance contains.

ttl(key, callback)

Get the time left before key expires. Returns null as res if the entry is not found.

flush(callback)

Flush all items from the engine instance.

expeditious-engine-memory's People

Contributors

evanshortiss avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.