-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
25 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,20 @@ | ||
import Enmap from 'enmap' | ||
import { Path } from 'glob' | ||
|
||
export default class Cache<Result>{ | ||
static all: Array<Enmap> = [] | ||
private cache!: Enmap<string, string> | ||
public name: string | ||
export default class Cache<Result> extends Enmap<string, string> { | ||
static all: Enmap<string, string>[] = [] | ||
|
||
constructor(key: string) { | ||
this.name = key | ||
this.loader(key) | ||
super({ name: key }) | ||
Cache.all.push(this) | ||
} | ||
|
||
private find (key: string) { | ||
return Cache.all.find((cache) => cache.name === key) | ||
} | ||
private create (key: string) { | ||
const newCache = new Enmap({ name: key }) | ||
Cache.all = [...Cache.all, newCache] | ||
return newCache | ||
} | ||
private loader(key: string) { | ||
let cache = this.find(key) | ||
if (cache === undefined) cache = this.create(key) | ||
this.cache = cache as Enmap<string, string> | ||
return this | ||
} | ||
|
||
get (): Result { | ||
return JSON.parse(String(this.cache.get('data'))) | ||
getData (): Result { | ||
return JSON.parse(this.get('data') ?? '{}') | ||
} | ||
save(data: Result) { | ||
this.cache.set('data', JSON.stringify(data)) | ||
super.set('data', JSON.stringify(data)) | ||
return this | ||
} | ||
exist() { return this.cache.has('data') } | ||
clear() { return this.cache.clear() } | ||
exist() { return this.has('data') } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters