wandering-eye/src/lib/ts-cache.ts

20 lines
379 B
TypeScript

import NodeCache from 'node-cache'
export default class TsCache<T> {
private cache: NodeCache
constructor(ttl: number) {
this.cache = new NodeCache({
stdTTL: ttl
})
}
has(key: string): boolean {
return this.cache.has(key)
}
get(key: string): T | undefined {
return <T>this.cache.get(key)
}
set(key: string, value: T): void {
this.cache.set(key, value)
}
}