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

memoizee-proxy

v0.1.9

Published

Memoize/cache function results

Downloads

936

Readme

memoizee-proxy

Build Status NPM Version

Read this in other languages: 简体中文

Memoize based on Proxy.

features

  • [x] Works with any type, any length of function arguments - optional serialization.
  • [x] Support for promises and asynchronous functions.
  • [x] Configurable weak provides a WeakMap (friendly garbage collection).
  • [x] Cache can be managed manually.
  • [x] Cache size can be limited on LRU basis.
  • [x] Optional reference counter mode, that allows more sophisticated cache management.
  • [x] unit tests.

API

| Property | Description | Type | Default | | :----| :---- | :---- | :---- | | normalizer | Generates a unique value based on the current parameter | (args: any[]) => string | Array.from(argument).join(',') | | weak | Using WeakMap | boolean | false | | maxAge | Timeout duration, expired delete | number | undefined | | max | Maximum number of items stored | number | undefined | | manual | Enable manage the cache manually | boolean | false | | refCounter | Enable reference counting | boolean | false | | dispose | Called right before an item is evicted from the cache | (value: T) => void | undefined | | closeable | Provide use cache toggle function | boolean | false |

Installation

npm install memoizee-proxy

or

yarn add memoizee-proxy

Usage

import {memoizee} from 'memoizee-proxy'

var fn = function(one, two, three) {
  /* ... */
};

var memoized = memoizee(fn);

memoized("foo", 3, "bar");
memoized("foo", 3, "bar"); // Cache hit
var afn = function(a, b) {
	return new Promise(function(res) {
		res(a + b);
	});
};
memoized = memoize(afn, { promise: true });

memoized(3, 7);
memoized(3, 7); // Cache hit

Changelog

0.1.9

  • The build tool was changed from microbundle to tsdx

0.1.6

  • Add the closeable parameter to operate on and off the cache

0.1.3

  • Modify the packaging tool to Rome (modify the default export)
  • Export the other two cache classes ExpiredLRUCache RefCache

0.0.4

  • fix cacheRef clear method missing cacheRef cleanup.
  • remove "max" and "maxAge" options cannot exist at the same time.

0.0.3

  • fix the options "max". if the added value is greater than or equal to max, throw error.

0.0.2

  • Basically completed, added max, maxAge to provide data management.
  • Manual is added to control the cache manually.
  • Reference count cache added.
  • Add the dispose function to call the control value when deleting data.
  • Add unit tests.

0.0.1

  • Basically available, add parameters "normalizer"、 "weak" 、"timeout"