Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

lru-cache 10.1.0

A cache object that deletes the least-recently-used items.
Package summary
Share
0
issues
0
licenses
Package created
16 Jul 2011
Version published
22 Nov 2023
Maintainers
1
Total deps
0
Direct deps
0
License
ISC
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does lru-cache do?

The "lru-cache" is a node package that provides a JavaScript implementation of a Least Recently Used (LRU) cache. An LRU cache deletes the least recently used items to make space for recently used items. You can specify a maximum number of the most recently used items, beyond which the least recently used items get deleted. Although primarily not a TTL cache, you can also set a Time to Live (TTL) on the cache or on a single "set" operation. As of version 7, "lru-cache" is noted as being one of the most performant JavaScript LRU cache implementations available. The library supports a wide variety of use cases, though utilizing some features may affect performance by increasing the workload of the cache.

How do you use lru-cache?

To use the "lru-cache" package in your JavaScript project, you first need to install it via npm by running npm install lru-cache --save in your terminal. Once installed, the "lru-cache" can be utilized by importing it into your JavaScript file. Here's an example of a minimal usage scenario:

const { LRUCache } = require('lru-cache');

const options = {
  max: 500,
  ttl: 1000 * 60 * 5, // 5 minutes in milliseconds
};

const cache = new LRUCache(options);

cache.set('key', 'value'); // set a value
console.log(cache.get('key')); // retrieve the value
cache.delete('key'); // delete value
cache.clear(); // empty the cache

The "lru-cache" module allows the use of non-string keys and setting of various options. For example, max storage limit, disposal mechanism for evicted objects, TTL, and setting asynchronous methods for cache.fetch() function.

Where are the lru-cache docs?

The documentation for the "lru-cache" is available on the GitHub repository of the package, under this URL: git://github.com/isaacs/node-lru-cache.git. The readme file in the main directory of the repository provides all the necessary information on how to install and use the package, as well as detailed descriptions of its features and options.