Socket
Socket
Sign inDemoInstall

lru-cache

Package Overview
Dependencies
0
Maintainers
0
Versions
134
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    lru-cache

A cache object that deletes the least-recently-used items.


Version published
Maintainers
0
Install size
6.51 kB
Created

Package description

What is lru-cache?

The lru-cache package is a JavaScript library that provides a cache object that deletes the least-recently-used items. It is useful for storing a limited amount of data in a way that allows for fast retrieval of entries based on keys.

What are lru-cache's main functionalities?

Creating a cache instance

This code sample demonstrates how to create a new LRU cache instance with a maximum of 500 items and a maximum age of one hour for each item.

{"const LRU = require('lru-cache');
const options = { max: 500, maxAge: 1000 * 60 * 60 };
const cache = new LRU(options);"}

Setting and getting cache items

This code sample shows how to set a value in the cache with a key and then retrieve that value using the same key.

{"const LRU = require('lru-cache');
const cache = new LRU();
cache.set('key', 'value');
const value = cache.get('key');"}

Checking if a key is in the cache

This code sample illustrates how to check if a key is present in the cache without updating the recent-ness or deleting it.

{"const LRU = require('lru-cache');
const cache = new LRU();
cache.set('key', 'value');
const hasKey = cache.has('key');"}

Deleting a key from the cache

This code sample shows how to delete a specific key from the cache.

{"const LRU = require('lru-cache');
const cache = new LRU();
cache.set('key', 'value');
cache.del('key');"}

Resetting the cache

This code sample demonstrates how to completely clear the cache.

{"const LRU = require('lru-cache');
const cache = new LRU();
cache.set('key', 'value');
cache.reset();"}

Other packages similar to lru-cache

Readme

Source

lru cache

A cache object that deletes the least-recently-used items.

Usage:

var LRU = require("lru-cache")
  , cache = LRU(10) // max 10 items. default = Infinity
cache.set("key", "value")
cache.get("key") // "value"

RTFS for more info.

FAQs

Last updated on 29 Jul 2011

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc