🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@digitalbazaar/lru-memoize

Package Overview
Dependencies
Maintainers
6
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@digitalbazaar/lru-memoize - npm Package Compare versions

Comparing version

to
2.2.0

6

CHANGELOG.md
# @digitalbazaar/lru-memoize ChangeLog
## 2.2.0 - 2022-02-27
### Added
- Allow cache `options` to be passed to `memoize`. Only cache options
that are supported by the underlying LRU instance will be used.
## 2.1.0 - 2021-06-30

@@ -4,0 +10,0 @@

17

lib/LruCache.js

@@ -26,4 +26,4 @@ /*!

export class LruCache {
constructor(cacheOptions) {
this.options = cacheOptions || {};
constructor(cacheOptions = {}) {
this.options = cacheOptions;
this.cache = new LRU(cacheOptions);

@@ -50,6 +50,9 @@ }

* promise to memoize.
* @param {object} options.options - The LRU cache options to pass
* if setting the value in the cache; note: only those options supported
* by the underlying LRU cache instance will be supported.
*
* @returns {Promise} - The result of the memoized promise.
*/
async memoize({key, fn}) {
async memoize({key, fn, options = {}} = {}) {
let promise = this.cache.get(key);

@@ -61,4 +64,8 @@ if(promise) {

// cache miss
const cacheOptions = {...this.options, ...options};
promise = fn();
this.cache.set(key, promise);
// this version only supports `maxAge` and `disposeOnSettle`; a future
// version will support more cache options
const {maxAge} = cacheOptions;
this.cache.set(key, promise, maxAge);

@@ -74,3 +81,3 @@ let result;

if(this.options.disposeOnSettle) {
if(cacheOptions.disposeOnSettle) {
this.cache.del(key);

@@ -77,0 +84,0 @@ }

{
"name": "@digitalbazaar/lru-memoize",
"version": "2.1.0",
"version": "2.2.0",
"description": "LRU Memoize",

@@ -5,0 +5,0 @@ "license": "BSD-3-Clause",