Giter VIP home page Giter VIP logo

node-cache's Introduction

node-cache

A simple in-memory cache for node.js

Installation

npm install memory-cache

Usage

var cache = require('memory-cache');

// now just use the cache

cache.put('foo', 'bar');
console.log(cache.get('foo'))

// that wasn't too interesting, here's the good part

cache.put('houdini', 'disappear', 100) // Time in ms
console.log('Houdini will now ' + cache.get('houdini'));

setTimeout(function() {
  console.log('Houdini is ' + cache.get('houdini'));
}, 200);

which should print

bar
Houdini will now disappear
Houdini is null

API

put = function(key, value, time)

  • Simply stores a value.
  • If time isn't passed in, it is stored forever.
  • Will actually remove the value in the specified time (via setTimeout).
  • Returns the cached value.

get = function(key)

  • Retrieves a value for a given key

del = function(key)

  • Deletes a key, return a bool specifying whether or not the key was deleted

clear = function()

  • Deletes all keys

size = function()

  • Returns the current number of entries in the cache

memsize = function()

  • Returns the number of entries taking up space in the cache
  • Will usually == size() unless a setTimeout removal went wrong

debug = function(bool)

  • Turns on or off debugging

hits = function()

  • Returns the number of cache hits

misses = function()

  • Returns the number of cache misses

keys = function()

  • Returns all the cache keys

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Send me a pull request.

node-cache's People

Contributors

ptarjan avatar bradleyg avatar vxst avatar austinpray avatar adambalogh avatar crabmusket avatar dblock avatar jasonrhodes avatar kemitchell avatar loris avatar lukehorvat avatar peterfriese avatar ramonsnir avatar wanasit avatar progame-ltd avatar alevicki avatar

Watchers

James Cloos 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.