t-lru-cahce

1.0.2 • Public • Published

T-LRU-CACHE

Build status

A LRU Cache module.

Installation:

npm install t-lru-cache --save

Useage

const TLRUCache = require("t-lru-cache");
const cache = new TLRUCache(10 /* capacity */); 

cache.put(1, 2);
cache.put('1', 3);
console.log(cahe.get(1)); // 2;
console.log(cahe.get('1')); // 3;

API

  • new TLRUCache(capacity)

    Return an t-lru-cache instance

  • put(key, value)

    It will update the "recently used"-ness of the key;

    If the key has in the cache, it will update it's value;

  • get(key) => value

    If the key is not found, get() will return -1.

    The key and val can be any value.

  • peek(key) => value

    Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

  • delete(key) => true/false

    Deletes a key out of the cache.

  • reset()

    Clear the cache entirely, throwing away all values.

  • has(key) => true/false

    Check if a key is in the cache, without updating the recent-ness or deleting it for being stale.

  • forEach(function(value[,key]))

    Iterates over all the keys in the cache, in order of recent-ness.

  • forEachRight(function(value[,key]))

    Iterates over all the keys in the cache, form right-to-left, in reverse order.

  • keys() => []

    Return all the keys in cache.

License

  MIT

Readme

Keywords

Package Sidebar

Install

npm i t-lru-cahce

Weekly Downloads

0

Version

1.0.2

License

MIT

Last publish

Collaborators

  • tonghuang