2.0.1 • Published 6 years ago

@kwiwk/lru-cache v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

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.