chronik-cache
Version:
A cache helper for chronik-client
69 lines (68 loc) • 1.82 kB
TypeScript
import { Level } from 'level';
interface DbUtilsOptions {
valueEncoding?: string;
maxCacheSize?: number;
enableLogging?: boolean;
failoverOptions?: any;
}
export default class DbUtils {
db: Level<string, any>;
private maxCacheSize;
cacheDir: string;
private failover;
private logger;
/**
* @param cacheDir Database file path
* @param options Optional parameters
*/
constructor(cacheDir: string, options?: DbUtilsOptions);
/**
* Unified DB read operation handler
*/
get(key: string, defaultValue?: any): Promise<any>;
/**
* Unified DB write operation handler
*/
put(key: string, value: any): Promise<void>;
/**
* Unified DB delete operation handler
*/
del(key: string): Promise<void>;
/**
* Calculate cache size
*/
calculateCacheSize(): Promise<number>;
/**
* Provide iterator interface for reading all key-value pairs
*/
iterator(): AsyncGenerator<[string, any], void, unknown>;
/**
* Clear database
*/
clear(): Promise<void>;
/**
* Clean least accessed entries in cache
*/
cleanLeastAccessedCache(): Promise<void>;
/**
* Clear all cache
*/
clearAll(): Promise<void>;
/**
* Delete data stored in a paginated manner.
*/
deletePaginated(keyBase: string): Promise<void>;
/**
* Unified DB token cache delete operation handler with pagination support
*/
clearTokenCache(tokenId: string): Promise<void>;
/**
* 添加用于存储全局元数据的方法
*/
updateGlobalMetadata(key: string, data: any): Promise<void>;
/**
* 添加用于获取全局元数据的方法
*/
getGlobalMetadata(key: string, defaultValue?: any): Promise<any>;
}
export {};