feat: 更新版本至 0.0.61,重构登录缓存逻辑,添加浏览器缓存支持
This commit is contained in:
29
query/query-login/browser-cache/cache.ts
Normal file
29
query/query-login/browser-cache/cache.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user