quick-lru

WebJar for quick-lru

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

quick-lru
Last Version

Last Version

5.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

quick-lru
WebJar for quick-lru
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/sindresorhus/quick-lru

Download quick-lru

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/quick-lru/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>quick-lru</artifactId>
    <version>5.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/quick-lru/
implementation 'org.webjars.npm:quick-lru:5.1.1'
// https://jarcasting.com/artifacts/org.webjars.npm/quick-lru/
implementation ("org.webjars.npm:quick-lru:5.1.1")
'org.webjars.npm:quick-lru:jar:5.1.1'
<dependency org="org.webjars.npm" name="quick-lru" rev="5.1.1">
  <artifact name="quick-lru" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='quick-lru', version='5.1.1')
)
libraryDependencies += "org.webjars.npm" % "quick-lru" % "5.1.1"
[org.webjars.npm/quick-lru "5.1.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

quick-lru Coverage Status

Simple β€œLeast Recently Used” (LRU) cache

Useful when you need to cache something and limit memory usage.

Inspired by the hashlru algorithm, but instead uses Map to support keys of any type, not just strings, and values can be undefined.

Install

$ npm install quick-lru

Usage

import QuickLRU from 'quick-lru';

const lru = new QuickLRU({maxSize: 1000});

lru.set('πŸ¦„', '🌈');

lru.has('πŸ¦„');
//=> true

lru.get('πŸ¦„');
//=> '🌈'

API

new QuickLRU(options?)

Returns a new instance.

options

Type: object

maxSize

Required
Type: number

The maximum number of items before evicting the least recently used items.

maxAge

Type: number
Default: Infinity

The maximum number of milliseconds an item should remain in cache. By default maxAge will be Infinity, which means that items will never expire.

Lazy expiration happens upon the next write or read call.

Individual expiration of an item can be specified by the set(key, value, options) method.

onEviction

Optional
Type: (key, value) => void

Called right before an item is evicted from the cache.

Useful for side effects or for items like object URLs that need explicit cleanup (revokeObjectURL).

Instance

The instance is an Iterable of [key, value] pairs so you can use it directly in a for…of loop.

Both key and value can be of any type.

.set(key, value, options?)

Set an item. Returns the instance.

Individual expiration of an item can be specified with the maxAge option. If not specified, the global maxAge value will be used in case it is specified on the constructor, otherwise the item will never expire.

.get(key)

Get an item.

.has(key)

Check if an item exists.

.peek(key)

Get an item without marking it as recently used.

.delete(key)

Delete an item.

Returns true if the item is removed or false if the item doesn't exist.

.clear()

Delete all items.

.resize(maxSize)

Update the maxSize, discarding items as necessary. Insertion order is mostly preserved, though this is not a strong guarantee.

Useful for on-the-fly tuning of cache sizes in live systems.

.keys()

Iterable for all the keys.

.values()

Iterable for all the values.

.entriesAscending()

Iterable for all entries, starting with the oldest (ascending in recency).

.entriesDescending()

Iterable for all entries, starting with the newest (descending in recency).

.size

The stored item count.

Related


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Versions

Version
5.1.1
4.0.1
1.1.0