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

@awsless/weak-cache

v0.0.1

Published

[![npm version](https://img.shields.io/npm/dw/@awsless/weak-cache)](https://www.npmjs.org/package/@awsless/weak-cache) [![npm version](https://img.shields.io/npm/v/@awsless/weak-cache.svg?style=flat-square)](https://www.npmjs.org/package/@awsless/weak-cac

Downloads

1,235

Readme

npm version npm version license

weak-cache

The @awsless/weak-cache package provides a fully typed simple cache that works with the JS garbage collection (GC). It uses weak references (and finalization registry) to allow GC to remove the cached data as part of the normal GC cycles, but still continue to provide cached access to the data as long as it still resides in memory and hasn't been collected.

Setup

Install with (NPM):

npm i @awsless/weak-cache

Basic Usage

import { WeakCache } from '@awsless/weak-cache';

// Create new WeakCache instance
const cache = new WeakCache<string, object>();

// Cache an empty object
cache.set('key', {});

// Return the object above as long as it is still cached
console.log(cache.get('key'));

// Return a boolean if the object above still exists in the cache
console.log(cache.has('key'));

// Delete a cached item
console.log(cache.delete('key'));

// Clear the cache
console.log(cache.clear());

// Return the amount of cached items
console.log(cache.size);

// Iterate over the cached items
for(const [ key, value ] of cache) {
	...
}

API

set(key, value)

Sets or inserts the value into the cache, with the given key.

get(key, defaultValue?)

Returns the value referenced by the given key. If the value is no longer cached, will return undefined or the provided default value.

has(key)

Returns a boolean indicating whether the cache with the specified key exists or not and still resided in memory and hasn't been collected.

delete(key)

Delete the value referenced by the given key.

clear()

Clear the entire cache

size

Return the amount of cached items that still resided in memory and hasn't been collected.

keys()

Return a iterable with keys of the cache

values()

Return a iterable with values of the cache

entries()

Return a iterable with both keys and values of the cache

License

MIT