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

an-lru-cache

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

an-lru-cache

A simple LRU Cache, a Map that has a maximum number of entries and which discards the least recently used items first.

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
decreased by-18.75%
Maintainers
1
Weekly downloads
 
Created
Source

ES6 LRU Cache

A simple LRU Cache, a Map that has a maximum number of entries and which discards the least recently used items first.

To install

$ npm install an-lru-cache

Coverage Status Build Status Dependencies Status npm

API

The API mirrors the builtin Map and WeakMap APIs but does not include iterators.

const { LruCache } = require('an-lru-cache')

const myCache = new LruCache()  // Default capacity is 100

function foo(key, value) {
  myCache.set(key, value)
  // ...
  return myCache.get(key)
}

function bar(key) {
  if (myCache.has(key)) {
    // ...
  }
  myCache.delete(key)
}

.set(key, value)

Associates value with key so that .get(key) returns value until a subsequent .set or .delete with the same key or eviction.

.get(key, fallbackValue=undefined)

Returns the value associated with key, or the fallbackValue if supplied.

Gets may return the fallbackValue even if there was a value associated with key if that entry was evicted to ensure that the number of entries did not exceed the maximum allowed.

.delete(key, fallbackValue=undefined)

Deletes any entry for the given key returning the previously associated value if present or fallbackValue otherwise.

.has(key)

True iff there is a value associated with key.

Keywords

FAQs

Package last updated on 11 Jun 2018

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