UNPKG

@ngx-toolkit/cache

Version:

Angular cache with Universal support

62 lines (61 loc) 3.17 kB
import 'reflect-metadata/Reflect'; export declare const METADATA_KEY_CACHE_DEFAULTS = "_cache_defaults"; export declare const METADATA_KEY_CACHE_KEYS = "_cache_keys"; export declare const METADATA_KEY_CACHE_VALUE = "_cache_value"; export interface CacheParams { cacheName?: string; } export interface CacheParamsInvoc extends CacheParams { afterInvocation?: boolean; } /** * Allows the configuration of defaults for `CacheResult`, `CachePut`, `CacheRemove`, and `CacheRemoveAll` at the class level. * Without the method level annotations this annotation has no effect. * * @param cacheName */ export declare function CacheDefaults(cacheName: string): ClassDecorator; /** * When a method annotated with `CacheResult` is invoked a cache key will be generated * and *Cache.get(key)* is called before the annotated method actually executes. * If a value is found in the cache it is returned and the annotated method is never actually executed. * If no value is found the annotated method is invoked and the returned value is stored in the cache with the generated key. * * @param params (Optional) {cacheName?: string} */ export declare function CacheResult(params?: CacheParams): MethodDecorator; /** * Marks a method argument as part of the cache key. * If no arguments are marked all arguments are used. * The exception is for a method annotated with `CachePut` where the `CacheValue` parameter is never included in the key. */ export declare function CacheKey(): ParameterDecorator; /** * When a method annotated with `CachePut` is invoked a cache key will be generated * and *Cache.put(key, value)* will be invoked on the specified cache storing the value marked with `CacheValue`. * * @param params (Optional) {cacheName?: string, afterInvocation: boolean = true} */ export declare function CachePut(params?: CacheParamsInvoc): MethodDecorator; /** * Marks the parameter to be cached for a method annotated with `CachePut`. */ export declare function CacheValue(): ParameterDecorator; /** * When a method annotated with `CacheRemove` is invoked a cache key will be generated * and *Cache.remove(key)* will be invoked on the specified cache. * The default behavior is to call *Cache.evict(key)* after the annotated method is invoked, * this behavior can be changed by setting *`afterInvocation`* to false in which case *Cache.evict(key)* * will be called before the annotated method is invoked. * * @param params (Optional) {cacheName?: string, afterInvocation: boolean = true} */ export declare function CacheRemove(params?: CacheParamsInvoc): MethodDecorator; /** * When a method annotated with `CacheRemoveAll` is invoked all elements in the specified cache will be removed via the *Cache.clear()* method. * The default behavior is to call *Cache.clear()* after the annotated method is invoked, * this behavior can be changed by setting *`afterInvocation`* to false in which case *Cache.clear()* will be called before the annotated method is invoked. * * @param params (Optional) {cacheName?: string, afterInvocation: boolean = true} */ export declare function CacheRemoveAll(params?: CacheParamsInvoc): MethodDecorator;