Skip to content

PlatformCacheInterceptor

@tsed/platform-cache

Usage

typescript
import { PlatformCacheInterceptor } from "@tsed/platform-cache";

See /packages/platform/platform-cache/src/interceptors/PlatformCacheInterceptor.ts.

Overview

ts
class PlatformCacheInterceptor implements InterceptorMethods {
    protected cache: PlatformCache;
    protected prefix: string;
    protected blacklist: string[];
    intercept(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext): unknown;
    canRefreshInBackground(key: string, { refreshThreshold, ttl, cachedTTL }: {
        refreshThreshold?: number;
        ttl: any;
        cachedTTL?: number;
    }, next: Function, $ctx?: Context): Promise<void>;
    cacheMethod(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext): Promise<any>;
    cacheResponse(interceptorContext: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext): Promise<any>;
    protected getMethod($ctx?: Context): string | undefined;
    protected noCache($ctx?: Context): boolean;
    protected getArgs(context: InterceptorContext<unknown, PlatformCacheOptions>): unknown[];
    protected getOptions(interceptorContext: InterceptorContext<any, PlatformCacheOptions>, defaultByPass?: PlatformCacheOptions["byPass"]): {
        key: string;
        refreshThreshold: number | undefined;
        ttl: import("../services/PlatformCache.js").Ttl | undefined;
        type: any;
        args: unknown[];
        collectionType: any;
        keyArgs: string;
        canCache: ((item: any) => boolean) | undefined;
        $ctx: Context;
        byPass: false | "no-cache" | ((args: any[], $ctx?: BaseContext) => boolean);
    };
    protected getContextFromArgs(args: unknown[]): Context | undefined;
    protected shouldByPassCache(byPass: PlatformCacheOptions["byPass"], args: unknown[], $ctx?: Context): boolean;
    protected hasKeyInQueue(key: string): Promise<boolean>;
    protected addKeyToQueue(key: string): Promise<void>;
    protected deleteKeyFromQueue(key: string): Promise<void>;
    protected acquireRefreshLock(key: string): Promise<() => void>;
    protected getRefreshCooldownKey(key: string): string;
    protected getRefreshThresholdWithJitter(key: string, refreshThreshold: number): number;
    protected hasRefreshCooldown(key: string): Promise<boolean>;
    protected addRefreshCooldown(key: string, refreshThreshold: number): Promise<void>;
    protected sendResponse(cachedObject: PlatformCachedObject): any;
}

protected cache

ts
protected cache: PlatformCache;

protected prefix

ts
protected prefix: string;

protected blacklist

ts
protected blacklist: string[];

intercept

ts
intercept(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext): unknown;

canRefreshInBackground

ts
canRefreshInBackground(key: string, { refreshThreshold, ttl, cachedTTL }: {
     refreshThreshold?: number;
     ttl: any;
     cachedTTL?: number;
 }, next: Function, $ctx?: Context): Promise<void>;

cacheMethod

ts
cacheMethod(context: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext): Promise<any>;

cacheResponse

ts
cacheResponse(interceptorContext: InterceptorContext<any, PlatformCacheOptions>, next: InterceptorNext): Promise<any>;

protected getMethod

ts
protected getMethod($ctx?: Context): string | undefined;

protected noCache

ts
protected noCache($ctx?: Context): boolean;

protected getArgs

ts
protected getArgs(context: InterceptorContext<unknown, PlatformCacheOptions>): unknown[];

protected getOptions

ts
protected getOptions(interceptorContext: InterceptorContext<any, PlatformCacheOptions>, defaultByPass?: PlatformCacheOptions["byPass"]): {
     key: string;
     refreshThreshold: number | undefined;
     ttl: import("../services/PlatformCache.js").Ttl | undefined;
     type: any;
     args: unknown[];
     collectionType: any;
     keyArgs: string;
     canCache: ((item: any) => boolean) | undefined;
     $ctx: Context;
     byPass: false | "no-cache" | ((args: any[], $ctx?: BaseContext) => boolean);
 };

protected getContextFromArgs

ts
protected getContextFromArgs(args: unknown[]): Context | undefined;

protected shouldByPassCache

ts
protected shouldByPassCache(byPass: PlatformCacheOptions["byPass"], args: unknown[], $ctx?: Context): boolean;

protected hasKeyInQueue

ts
protected hasKeyInQueue(key: string): Promise<boolean>;

protected addKeyToQueue

ts
protected addKeyToQueue(key: string): Promise<void>;

protected deleteKeyFromQueue

ts
protected deleteKeyFromQueue(key: string): Promise<void>;

protected acquireRefreshLock

ts
protected acquireRefreshLock(key: string): Promise<() => void>;

protected getRefreshCooldownKey

ts
protected getRefreshCooldownKey(key: string): string;

protected getRefreshThresholdWithJitter

ts
protected getRefreshThresholdWithJitter(key: string, refreshThreshold: number): number;

protected hasRefreshCooldown

ts
protected hasRefreshCooldown(key: string): Promise<boolean>;

protected addRefreshCooldown

ts
protected addRefreshCooldown(key: string, refreshThreshold: number): Promise<void>;

protected sendResponse

ts
protected sendResponse(cachedObject: PlatformCachedObject): any;

Released under the MIT License.