1.0.2 • Published 10 years ago

yascjs v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 years ago

yascjs

A simple in-memory cache with record expiry for javascript. This library has no run-time dependencies and is CommonJS and AMD compatible. Includes tests.

Installing

npm install yascjs

Usage

var Cache = require("yascjs");
var cache = new Cache();

//Adding a record that expires after 1 second ...
cache.put("Recent Episode", "The City on the Edge of Forever", 1000);
cache.get("Recent Episode"); //returns "The City on the Edge of Forever"

setTimeout(function(){
  cache.get("Recent Episode"); //returns null
}, 1000);


//Alternatively if no expiry is required ...
cache.put("Favourite Episode", "A Piece of the Action");

API

put(key, value, [ttl])

Adds a record to the cache mapping key to value. Optionally have an expiry time in ttl milliseconds. After the ttl is expired, the record is removed from the cache.

get(key)

Retrives the value associated with the key;

del(key)

Immediately removes a record associated with the key;

clear()

Removes all records from the cache.

size()

The number of unexpired records in the cache;

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago