New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

lru-memory-cache

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lru-memory-cache

Simple in-memory cache implementation with LRU

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

LRU-memory-cache

Simple in-memory cache implementation for Node.js

Installation

npm install --save LRU-memory-cache

Usage example

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

// Create cache
var cache = new MemoryCache();

// Get/set value
var val = cache.get('key'); // undefined
cache.set('key', 'value', ttl);
val = cache.get('key'); // 'value'

// Delete value
cache.delete('key');
val = cache.get('key'); // undefined

// Set value which will expire after 1 second
cache.set('key', 'new-value', 1);
setTimeout(function () {
    val = cache.get('key'); // undefined
}, 1000);

cache.set('key', 'new-value', 1);
setTimeout(function () {
    val = cache.get('key'); // new-value (exist)
}, 900);

setTimeout(function () {
    val = cache.get('key'); // still exists
}, 900);

// each get move 'used' timestamp further. So TTL means time-from-last-use. LRU cache.


Running tests

npm install
npm test

Keywords

memory

FAQs

Package last updated on 25 Feb 2016

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