Socket
Socket
Sign inDemoInstall

@digitalbazaar/lru-memoize

Package Overview
Dependencies
2
Maintainers
6
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.0 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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc