|
|
@ -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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -172,7 +172,7 @@ export class Cache<K extends string | number | symbol, T> {
|
|
|
|
* @return {this}
|
|
|
|
* @return {this}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
set(key: K, value: T, ttl = this.options.ttl): this {
|
|
|
|
set(key: K, value: T, ttl = this.options.ttl): this {
|
|
|
|
if(this.options.expiryPolicy == 'keep') delete (<any>this.store[key])._expired;
|
|
|
|
if(this.options.expiryPolicy == 'keep') delete (<any>value)._expired;
|
|
|
|
this.store[key] = value;
|
|
|
|
this.store[key] = value;
|
|
|
|
this.save();
|
|
|
|
this.save();
|
|
|
|
if(ttl) setTimeout(() => {
|
|
|
|
if(ttl) setTimeout(() => {
|
|
|
|