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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@wealthbar/data-cache

v1.1.0

Published

Client side data cache

Downloads

3

Readme

data-cache

Provides a client side in-memory, limited size, data cache for storing results from server calls. It uses least-recently accessed (with a maximum) eviction algorithm instead of strict LRU.

dataCacheCtor({maxWeight,maxAccessed}): dataCacheType

function dataCacheCtor(
  {
    maxWeight,
    maxAccessed,
  }: {
    maxWeight?: number,
    maxAccessed?: number,
  } = {}
): dataCacheType

Returns a new dataCache. maxWeight defaults to 1000000 and maxAccessed defaults to 8. "Weight" is used instead of a specific size measurement; dataCacheObjectWeight is provided as a default method for computing the relative space requirements of an object and it's lookup key. Since we can't assume all objects stored will be JSON serializable (or that the user wants to take that performance hit) the user is still responsible for providing the weight of each entry in the cache (including the key size).

dataCacheObjectWeight({key,entry}):number

function dataCacheObjectWeight(
  {
    key,
    entry,
  }: {
    key: string,
    entry: object | undefined,
  }
): number

Convenience function to compute the weight of a "POJO".

dataCacheEvict({dataCache,key}):void

function dataCacheEvict(
  {
    dataCache,
    key,
  }: {
    dataCache: dataCacheType,
    key: string,
  }
):void

Evicts key from the dataCache.

dataCacheReap({ dataCache,weight}):void

function dataCacheReap(
  {
    dataCache,
    weight,
  }: {
    dataCache: dataCacheType,
    weight: number,
  }
): void

Remove entries from the cache until a new entry of weight can be added without exceeding the maxWeight. This will throw if weight exceeded maxWeight (i.e. the entry can't fit in the cache).

dataCachePut({dataCache,key,entry,weight}):void

function dataCachePut(
  {
    dataCache,
    key,
    entry,
    weight,
  }: {
    dataCache: dataCacheType,
    key: string,
    entry: object | undefined,
    weight: number,
  }
): void

Adds an entry to the dataCache under the key key, evicting if needed to accommodate its weight.

dataCacheGet({dataCache,key,peek}): object | undefined

function dataCacheGet(
  {
    dataCache,
    key,
    peek,
  }: {
    dataCache: dataCacheType,
    key: string,
    peek?: boolean,
  }
): object | undefined

Retrieves an entry from the dataCache under the key key. If peek is true the access count is not incremented. If the entry is not in the cache (evicted or never been added) undefined is returned.