Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-lrucache

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-lrucache

Javascript implementation of least recently used cache

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

js-lrucache

least recently used cache implemented using ES6 and Babel

Install

Run the following command:

npm install js-lrucache

Usage

import LRUCache from 'js-lrucache';

let cache = new LRUCache(4); // max capacity is 4
cache.put('a', { value: 1 });
cache.put('b', { value: 2 });
cache.put('c', { value: 3 });
cache.put('d', { value: 4 });
console.log(cache.size()); // display 4
cache.put('e', { value: 5 }); // 'a' gets removed as capacity is only 4 and 'a' is the oldest item stored
console.log(cache.size()); // display 4;
console.log(cache.get('a')); // display undefined as cache now contains only 'b', 'c', 'd', 'e'
cache.get('b'); // 'b' has been access recently 
cache.put('f', { value: 6 }); // 'c' gets removed as 'b' access more recently than 'c'
console.log(cache.get('b')); // display { value: 2 }
console.log(cache.get('c')); // display undefined as 'c' has been removed 

let cache2 = cache.deepCopy();
console.log(cache2.get('b')); // display { value: 2 }

Keywords

FAQs

Package last updated on 09 Sep 2017

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