New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jonathan

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jonathan

An in-memory cache for Node

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
decreased by-54.17%
Maintainers
1
Weekly downloads
 
Created
Source

Jonathan Build status

An in-memory cache for Node

Installation

Jonathan can be installed into your project via npm:

npm install jonathan --save

Basic usage

'use strict';

var http = require('http'),
	jonathan = require('jonathan'),
	server;

jonathan.init();

server = http.createServer(function (req, res) {
 	jonathan.add('name', 'James');
 	res.writeHead(200, {"Content-Type": "text/plain"});
	res.end('The name stored in Jonathan is: ' + jonathan.get('name'));
});

server.listen(3000);
console.log('Listening on port 3000');

APIs

Number.prototype polyfills

This module attaches a set of methods to Number's prototype so that you can write durations more fluently, such as:

jonathan.add('key', 'value', (2).weeks);
jonathan.add('key2', 'value', (5).months);

These methods simply multiply the Number object on which you've called the method by a predefined amount of milliseconds. You should never need to invoke them yourself; Jonathan will do it for you.

Here are all of the attached methods:

  • Number.prototype.seconds
  • Number.prototype.minutes
  • Number.prototype.hours
  • Number.prototype.days
  • Number.prototype.weeks
  • Number.prototype.months
  • Number.prototype.years

jonathan

####init() - Function Initialises the cache. You must call this before you can use Jonathan.

####invalidate() - Function Invalidates the entire cache

####add(key, value, duration) - Function Adds an object to the cache under a specific key. If the duration parameter is not specified, it will be stored indefinitely, otherwise a function returning a Number is required (see Number.prototype polyfills.)

####get(key) - Function Retrieves a value from the cache by the specified key. If the key is not present in the cache, this method will return undefined.

####remove(key) - Function Removes a key, and its accompanying value, from the cache.

Tests

Jonathan was written using test-driven development (TDD) with Mocha. To run the tests, clone the repository, install Mocha globally, and invoke it at the command line within the project's directory:

mocha tests/*

Keywords

FAQs

Package last updated on 23 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc