@kwiwk/lru-cache
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

lru-cache

A cache for asychnronous data.

Travis Coveralls github npm npm

Kwiwk Logo

Table Of Contents

Description

LRUCache will cache data and throw away old or expired values.

Features:

  • First class TypeScript support!
  • Configurable expiration time
  • Configurable LRU cache size

Getting Started

  • Install Node v8 LTS here.

Documentation

import { LRUCachedGetter } from "@kwiwk/lru-cache";

async function getPersonById(id: number): Promise<Person> {
    // Get get a person by their ID asynchronously
}

async function personIdToString(id: number): string {
    return id.toString();
}

// Create a new LRU cache
const lru = new LRUCached<string, number>(
    hasher: name => name.toLowercase(),

    // Maximum size of LRU cache (defaults to 10000).
    maxSize: 10,

    // Milliseconds until the cached entry expires (defaults to Infinity).
    expiresMs: 1000 * 60 * 60 * 24
});

lru.set("Russley", 24);

lru.get("russley"); // 24
lru.get("Alice"); // undefined
lru.getOrDefault("Bob", 0); // 0

View the API docs here.

View the coverage report here.

License

View the license here.

Changelog

View the changelog here.

Readme

Keywords

none

Package Sidebar

Install

npm i @kwiwk/lru-cache

Weekly Downloads

1

Version

2.0.1

License

MIT

Unpacked Size

94.7 kB

Total Files

14

Last publish

Collaborators

  • russleyshaw