|
|
|
@ -15,8 +15,6 @@ export interface Cache<V = any> {
@@ -15,8 +15,6 @@ export interface Cache<V = any> {
|
|
|
|
|
|
|
|
|
|
const NOT_ALIVE = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class Memory<T = any, V = any> { |
|
|
|
|
private cache: { [key in keyof T]?: Cache<V> } = {}; |
|
|
|
|
private readonly alive: number; |
|
|
|
@ -29,7 +27,7 @@ export class Memory<T = any, V = any> {
@@ -29,7 +27,7 @@ export class Memory<T = any, V = any> {
|
|
|
|
|
return this.cache; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setCache(cache: { [key in keyof T]?: Cache<V> }) { |
|
|
|
|
setCache(cache) { |
|
|
|
|
this.cache = cache; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -94,8 +92,8 @@ export class Memory<T = any, V = any> {
@@ -94,8 +92,8 @@ export class Memory<T = any, V = any> {
|
|
|
|
|
|
|
|
|
|
clear() { |
|
|
|
|
Object.keys(this.cache).forEach((key) => { |
|
|
|
|
const item = this.get(<any>key); |
|
|
|
|
item?.timeoutId && clearTimeout(item.timeoutId); |
|
|
|
|
const item = this.cache[key]; |
|
|
|
|
item.timeoutId && clearTimeout(item.timeoutId); |
|
|
|
|
}); |
|
|
|
|
this.cache = {}; |
|
|
|
|
} |
|
|
|
|