cache.d.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { entityKind } from "../../entity.js";
  2. import type { Table } from "../../index.js";
  3. import type { CacheConfig } from "./types.js";
  4. export declare abstract class Cache {
  5. static readonly [entityKind]: string;
  6. abstract strategy(): 'explicit' | 'all';
  7. /**
  8. * Invoked if we should check cache for cached response
  9. * @param sql
  10. * @param tables
  11. */
  12. abstract get(key: string, tables: string[], isTag: boolean, isAutoInvalidate?: boolean): Promise<any[] | undefined>;
  13. /**
  14. * Invoked if new query should be inserted to cache
  15. * @param sql
  16. * @param tables
  17. */
  18. abstract put(hashedQuery: string, response: any, tables: string[], isTag: boolean, config?: CacheConfig): Promise<void>;
  19. /**
  20. * Invoked if insert, update, delete was invoked
  21. * @param tables
  22. */
  23. abstract onMutate(params: MutationOption): Promise<void>;
  24. }
  25. export declare class NoopCache extends Cache {
  26. strategy(): "all";
  27. static readonly [entityKind]: string;
  28. get(_key: string): Promise<any[] | undefined>;
  29. put(_hashedQuery: string, _response: any, _tables: string[], _config?: any): Promise<void>;
  30. onMutate(_params: MutationOption): Promise<void>;
  31. }
  32. export type MutationOption = {
  33. tags?: string | string[];
  34. tables?: Table<any> | Table<any>[] | string | string[];
  35. };
  36. export declare function hashQuery(sql: string, params?: any[]): Promise<string>;