koatty_cacheable
Version:
Cacheable for koatty.
94 lines (83 loc) • 2.53 kB
TypeScript
/*!
* @Author: richen
* @Date: 2025-06-23 01:59:58
* @License: BSD (3-Clause)
* @Copyright (c) - <richenlin(at)gmail.com>
* @HomePage: https://koatty.org/
*/
import { Koatty } from 'koatty_core';
export declare const CACHE_METADATA_KEY = "CACHE_METADATA_KEY";
/**
* Decorate this method to support caching.
* The cache method returns a value to ensure that the next time
* the method is executed with the same parameters, the results can be obtained
* directly from the cache without the need to execute the method again.
* CacheStore server config defined in db.ts.
*
* @export
* @param {string} cacheName cache name
* @param {CacheAbleOpt} [opt] cache options
* e.g:
* {
* params: ["id"],
* timeout: 30
* }
* Use the 'id' parameters of the method as cache subkeys, the cache expiration time 30s
* @returns {MethodDecorator}
*/
export declare function CacheAble(cacheNameOrOpt?: string | CacheAbleOpt, opt?: CacheAbleOpt): MethodDecorator;
/**
* @description: CacheAble decorator options
*/
export declare interface CacheAbleOpt {
params?: string[];
timeout?: number;
cacheName?: string;
}
/**
* Decorating the execution of this method will trigger a cache clear operation.
* CacheStore server config defined in db.ts.
*
* @export
* @param {string} cacheName cacheName cache name
* @param {CacheEvictOpt} [opt] cache options
* e.g:
* {
* params: ["id"],
* delayedDoubleDeletion: true
* }
* Use the 'id' parameters of the method as cache subkeys,
* and clear the cache after the method executed
* @returns
*/
export declare function CacheEvict(cacheNameOrOpt?: string | CacheEvictOpt, opt?: CacheEvictOpt): MethodDecorator;
/**
* @description: CacheEvict decorator options
*/
export declare interface CacheEvictOpt {
params?: string[];
delayedDoubleDeletion?: boolean;
cacheName?: string;
}
declare interface CacheOptions {
cacheTimeout?: number;
delayedDoubleDeletion?: boolean;
redisConfig?: RedisConfig;
}
export declare enum DecoratorType {
CACHE_EVICT = "CACHE_EVICT",
CACHE_ABLE = "CACHE_ABLE"
}
/**
* @param options - The options for the scheduled job
* @param app - The Koatty application instance
*/
export declare function KoattyCache(options: CacheOptions, app: Koatty): Promise<void>;
declare interface RedisConfig {
host?: string;
port?: number;
password?: string;
db?: number;
keyPrefix?: string;
}
export { }