0.1.9 • Published 3 years ago

memoizee-proxy v0.1.9

Weekly downloads
9
License
MIT
Repository
github
Last release
3 years ago

memoizee-proxy

Build Status NPM Version

Read this in other languages: 简体中文

Memoize based on Proxy.

features

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

API

PropertyDescriptionTypeDefault
normalizerGenerates a unique value based on the current parameter(args: any[]) => stringArray.from(argument).join(',')
weakUsing WeakMapbooleanfalse
maxAgeTimeout duration, expired deletenumberundefined
maxMaximum number of items storednumberundefined
manualEnable manage the cache manuallybooleanfalse
refCounterEnable reference countingbooleanfalse
disposeCalled right before an item is evicted from the cache(value: T) => voidundefined
closeableProvide use cache toggle functionbooleanfalse

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"
0.1.8

3 years ago

0.1.9

3 years ago

0.1.6

3 years ago

0.1.2

3 years ago

0.1.3

3 years ago

0.1.5

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago