Comparing version 0.2.44 to 0.2.45
@@ -23,3 +23,4 @@ /** | ||
export function getAsync<K, V>(cache: Cache<K, V>, key: K): V | Promise<V> | undefined; | ||
export function setIfUndefined<K, V>(cache: Cache<K, V>, key: K, init: () => Promise<V>): V | Promise<V>; | ||
export function remove<K, V>(cache: Cache<K, V>, key: K): V | undefined; | ||
export function setIfUndefined<K, V>(cache: Cache<K, V>, key: K, init: () => Promise<V>, removeNull?: boolean): V | Promise<V>; | ||
export function create(timeout: number): Cache<any, any>; | ||
@@ -26,0 +27,0 @@ import * as list from "./list.js"; |
23
cache.js
@@ -7,3 +7,3 @@ | ||
* | ||
* @module cached-map | ||
* @module cache | ||
*/ | ||
@@ -150,6 +150,22 @@ | ||
* @param {K} key | ||
*/ | ||
export const remove = (cache, key) => { | ||
const n = cache._map.get(key) | ||
if (n) { | ||
list.removeNode(cache._q, n) | ||
cache._map.delete(key) | ||
return n.val && !(n.val instanceof Promise) ? n.val : undefined | ||
} | ||
} | ||
/** | ||
* @template K, V | ||
* | ||
* @param {Cache<K, V>} cache | ||
* @param {K} key | ||
* @param {function():Promise<V>} init | ||
* @param {boolean} removeNull Optional argument that automatically removes values that resolve to null/undefined from the cache. | ||
* @return {Promise<V> | V} | ||
*/ | ||
export const setIfUndefined = (cache, key, init) => { | ||
export const setIfUndefined = (cache, key, init, removeNull = false) => { | ||
const now = removeStale(cache) | ||
@@ -172,2 +188,5 @@ const q = cache._q | ||
} | ||
if (removeNull && v == null) { | ||
remove(cache, key) | ||
} | ||
}) | ||
@@ -174,0 +193,0 @@ return p |
@@ -23,3 +23,4 @@ /** | ||
export function getAsync<K, V>(cache: Cache<K, V>, key: K): V | Promise<V> | undefined; | ||
export function setIfUndefined<K, V>(cache: Cache<K, V>, key: K, init: () => Promise<V>): V | Promise<V>; | ||
export function remove<K, V>(cache: Cache<K, V>, key: K): V | undefined; | ||
export function setIfUndefined<K, V>(cache: Cache<K, V>, key: K, init: () => Promise<V>, removeNull?: boolean): V | Promise<V>; | ||
export function create(timeout: number): Cache<any, any>; | ||
@@ -26,0 +27,0 @@ import * as list from "./list.js"; |
{ | ||
"name": "lib0", | ||
"version": "0.2.44", | ||
"version": "0.2.45", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2334136
32360
1342