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

@vltpkg/cache

v0.0.0-0.1730724342581

Published

The filesystem cache for `@vlt/registry-client`

Downloads

11

Readme

cache

@vltpkg/cache

The filesystem cache for @vlt/registry-client, but also, a general-purpose filesystem-backed LRUCache

Usage · Note

Overview

This is very minimal on features, because it has a very narrow use case, but if you want to have a persistently fs-backed LRU memory cache of Buffers using strings as keys, then this is the thing to use.

Usage

import { Cache } from '@vltpkg/cache'

const numberOfItemsToKeepInMemory = 10_000

const cache = new Cache({
  path: '/path/to/fs/cache/folder',
  // the number of items to keep in memory
  // on-disk folder will just keep everything
  // see @vltpkg/cache-manager for handling that
  max: 10_000,
})

// reading is always async, because it has to go to disk maybe
// this is a wrapper around an LRUCache#fetchMethod that reads
// from the file system
const someCachedValue = await cache.fetch(someKey)

// fetch by integrity, if available:
const integrity =
  'sha512-6/mh1E2u2YgEsCHdY0Yx5oW+61gZU+1vXaoiHHrpKeuRNNgFvS+/jrwHiQhB5apAf5oB7UB7E19ol2R2LKH8hQ=='
const valueByInt = await cache.fetch('blah', {
  context: { integrity },
})

// synchronous cache read, will only return a value if present in
// the memory cache. Does *not* fall back to the fs store.
const valueFromMemoryCache = cache.get(someKey)

// synchronous cache read, which does fall back to the fs store,
// using synchronous file I/O
const valueUsingSyncFileSystemOps = cache.fetchSync(someKey)

// set operations are atomically written to the fs cache in the
// background but are available immediately because they are
// added to the memory cache first
cache.set('some-key', Buffer.from('some-value'))

// set with integrity creates a hard-linked file at the content
// address, so that anyone fetching the same content by any other
// key will get the same result.
cache.set(someKey, someValue, { integrity })
await cache.promise() // once it's done writing...
// returns identical bits as someValue, because on-disk cache
// hard links to a file based on the integrity value.
const otherValue = await cache.fetch(otherKey, {
  context: { integrity },
})

Note

  • The key type must be a string. It gets sha512 hashed to determine the file on disk.
  • The value must be a Buffer, so that it can be written to a file and read from it without having to convert anything.