Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
76b570b3fe | |||
4fecf10d11 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.24.9",
|
"version": "0.24.11",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -11,7 +11,7 @@ export type CacheOptions = {
|
|||||||
expiryPolicy?: 'delete' | 'keep';
|
expiryPolicy?: 'delete' | 'keep';
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CachedValue<T> = T | {_expired?: boolean};
|
export type CachedValue<T> = T & {_expired?: boolean};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of data which tracks whether it is a complete collection & offers optional expiry of cached values
|
* Map of data which tracks whether it is a complete collection & offers optional expiry of cached values
|
||||||
@ -119,7 +119,7 @@ export class Cache<K extends string | number | symbol, T> {
|
|||||||
*/
|
*/
|
||||||
entries(expired?: boolean): [K, CachedValue<T>][] {
|
entries(expired?: boolean): [K, CachedValue<T>][] {
|
||||||
return deepCopy<any>(Object.entries(this.store)
|
return deepCopy<any>(Object.entries(this.store)
|
||||||
.filter((v: any) => expired || !v._expired));
|
.filter((v: any) => expired || !v?._expired));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,7 +139,7 @@ export class Cache<K extends string | number | symbol, T> {
|
|||||||
*/
|
*/
|
||||||
get(key: K, expired?: boolean): T | null {
|
get(key: K, expired?: boolean): T | null {
|
||||||
const cached = deepCopy<any>(this.store[key] ?? null);
|
const cached = deepCopy<any>(this.store[key] ?? null);
|
||||||
if(expired || !cached._expired) return cached;
|
if(expired || !cached?._expired) return cached;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user