npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tenure

v1.2.0

Published

An manageable LRU cache and configurable eviction policy

Downloads

2

Readme

Build
Status npm version License: MIT

Tenure | Manageable LRU caching

Tenure is a manageable LRU cache instance that uses hashmap lookups and an Open Doubly Linked List to enact the Least-Recently Used algorithm

Installation

npm install tenure

OR

yarn add tenure

LRU Cache Algorithm

Supported Environments

Tenure currently supports UMD, CommonJS (node versions >= 10), and ESM build-targets

Commonjs:

var LruCache = require('tenure');

var cache = new LruCache(100, cb);

ESM:

import LruCache from 'tenure';

const cache = new LruCache(100, cb);

API Reference

LruCache

new LruCache(capacity, cb)

Implements a canonical Least Recently-Used Cache

| Param | Type | Description | | --- | --- | --- | | capacity | number | The maximum capacity (items) of the cache; beyond this threshold, the eviction policy is enacted. Defaults to 10 | | cb | function | Optional callback to be invoked upon each eviction; called with evicted item key, value |

lruCache.get(key) ⇒ any | null

Retrieve an item from the cache; if extant, the item will be designated 'most-recently used' Returns: any | null - The retrieved value, if extant; else, null

| Param | Type | | --- | --- | | key | any |

lruCache.put(key, value) ⇒ boolean

Add or update a given key / value pair in the cache

Put transactions will move the key to the head of the cache, designating it as 'most recently-used'

If the cache has reached the specified capacity, Put transactions will also enact the eviction policy, thereby removing the least recently-used item Returns: boolean - A boolean indicating whether an eviction occurred

| Param | Type | | --- | --- | | key | any | | value | any |

lruCache.del(key) ⇒ boolean

Remove an item corresponding to a given key from the cache, if extant Returns: boolean - A boolean indicating whether of not the delete transaction occurred

| Param | Type | | --- | --- | | key | any |

lruCache.keys() ⇒

Returns: An array of all keys currently extant in the cache

lruCache.has(key) ⇒

Verify the existence of a key in the cache without enacting the eviction policy Returns: A boolean flag verifying the existence (or lack thereof) of a given key in the cache

| Param | Type | | --- | --- | | key | any |

lruCache.lru() ⇒ array | null

Returns: array | null - the least recently-used key / value pair, or null if not extant

lruCache.drop()

Drop all items from the cache, effectively purging it

lruCache.resize(cap) ⇒ number

Resizes the cache capacity.

Invoking this transaction will evict all least recently-used items to adjust the cache, where necessary Returns: number - the number of evictions enacted

| Param | Type | Description | | --- | --- | --- | | cap | number | new capacity |

lruCache.size() ⇒ number

Returns: number - the current size of the cache

lruCache.capacity() ⇒ number

Returns: number - the current maximum buffer capacity of the cache