teeny-lru
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Teeny LRU

Least Recently Used cache

import { createLRU } from "teeny-lru";

const cache = createLRU({
  max: 100,
  ttl: 0,
  onDispose(key, value) {
    console.log(`Disposed ${key}`);
  },
});

// Clears the contents of the cache
cache.clear();

// Removes item from cache
cache.delete("key");

// Evicts the least recently used item from cache
cache.evict();

// Gets cached item and moves it to the front
cache.get("key");

// Returns an `Array` of cache item keys.
cache.keys();

// Sets item in cache as `first`
cache.set("myKey", { prop: true });

// Removes stale items
cache.prune();

// Number of items in cache
cache.size();

License

Copyright (c) 2021 Kamil Kisiela Licensed under the MIT license.

Package Sidebar

Install

npm i teeny-lru

Weekly Downloads

5

Version

1.0.0

License

MIT

Unpacked Size

12.2 kB

Total Files

7

Last publish

Collaborators

  • kamilkisiela