30 lines
829 B
TypeScript
30 lines
829 B
TypeScript
export { CacheStore, BaseCacheStore } from './cache-store.ts'
|
||
import { CacheStore } from './cache-store.ts'
|
||
|
||
/**
|
||
* 一个简单的缓存类,用于存储字符串。
|
||
* 对数据进行添加对比内容。
|
||
*/
|
||
export class MyCache<T = any> extends CacheStore {
|
||
key: string;
|
||
constructor(opts?: { key?: string }) {
|
||
const { key, ...rest } = opts || {};
|
||
super(rest);
|
||
this.key = key || 'my-cache';
|
||
}
|
||
async getData<U = T>(key: string = this.key): Promise<U> {
|
||
return super.getCheckData<U>(key) as any;
|
||
}
|
||
/**
|
||
* 设置缓存数据,默认过期时间为10天
|
||
* @param data
|
||
* @param opts
|
||
*/
|
||
async setData<U = T>(data: U, opts?: { expireTime?: number, updatedAt?: number }) {
|
||
super.setCheckData(this.key, data, opts);
|
||
}
|
||
async del(): Promise<void> {
|
||
await super.del(this.key);
|
||
}
|
||
}
|