Skip to content

Commit

Permalink
feat: add CacheType
Browse files Browse the repository at this point in the history
to generify `Cache` sctructure
  • Loading branch information
dimaslanjaka committed May 14, 2023
1 parent 55ab91f commit d233f1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/CacheMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,18 @@ export class CacheMapper<K, V> implements Map<K, V> {
this.size = this._innerMap.size;
}
}

export interface CacheType<V> {
cache: CacheMapper<string, V>;
has(key: string): boolean;
get(key: string): V;
set(key: string, value: V): CacheMapper<string, V>;
dump(): {
[k: string]: V;
};
size(): number;
apply(key: string, value: V): V;
apply(key: string, value: () => V): V;
del(key: string): void;
flush(): void;
}
4 changes: 2 additions & 2 deletions lib/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CacheMapper } from './CacheMapper';
import { CacheMapper, CacheType } from './CacheMapper';

export = class Cache<V> {
export = class Cache<V> implements CacheType<V> {
cache: CacheMapper<string, V>;
constructor() {
this.cache = new CacheMapper<string, V>();
Expand Down

0 comments on commit d233f1b

Please sign in to comment.