This commit is contained in:
cool 2024-03-26 11:42:00 +08:00
parent fb32283ded
commit e686095ea2
3 changed files with 128 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
logs/
cache/
npm-debug.log
yarn-error.log
node_modules/

64
core/src/cache/store.ts vendored Normal file
View File

@ -0,0 +1,64 @@
import * as FsStore from "@cool-midway/cache-manager-fs-hash";
/**
* cool
*/
class FsCacheStore {
options: any;
store: FsStore;
constructor(options = {}) {
options = {
...options,
path: "cache",
ttl: -1,
};
this.options = options;
this.store = FsStore.create(options);
}
/**
*
* @param key
* @returns
*/
async get<T>(key: string): Promise<T> {
return await this.store.get(key);
}
/**
*
* @param key
* @param value
* @param ttl
*/
async set<T>(key: string, value: T, ttl: number): Promise<void> {
let t = ttl ? ttl : this.options.ttl;
if (t > 0) {
t = t / 1000;
}
await this.store.set(key, value, {
ttl: t,
});
}
/**
*
* @param key
*/
async del(key: string): Promise<void> {
await this.store.del(key);
}
/**
*
*/
async reset(): Promise<void> {
await this.store.reset();
}
}
export const CoolCacheStore = function (options = {}) {
return new FsCacheStore(options);
};

64
plugin-cli/src/cache/store.ts vendored Normal file
View File

@ -0,0 +1,64 @@
import * as FsStore from "@cool-midway/cache-manager-fs-hash";
/**
* cool
*/
export class FsCacheStore {
options: any;
store: FsStore;
constructor(options = {}) {
options = {
...options,
path: "cache",
ttl: -1,
};
this.options = options;
this.store = FsStore.create(options);
}
/**
*
* @param key
* @returns
*/
async get<T>(key: string): Promise<T> {
return await this.store.get(key);
}
/**
*
* @param key
* @param value
* @param ttl
*/
async set<T>(key: string, value: T, ttl?: number): Promise<void> {
let t = ttl ? ttl : this.options.ttl;
if (t > 0) {
t = t / 1000;
}
await this.store.set(key, value, {
ttl: t,
});
}
/**
*
* @param key
*/
async del(key: string): Promise<void> {
await this.store.del(key);
}
/**
*
*/
async reset(): Promise<void> {
await this.store.reset();
}
}
export const CoolCacheStore = function (options = {}) {
return new FsCacheStore(options);
};