Files
query-awesome/query/query-login/browser-cache/cache.ts

30 lines
829 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}