cache.d.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Redis } from '@upstash/redis';
  2. import type { MutationOption } from "../core/index.js";
  3. import { Cache } from "../core/index.js";
  4. import { entityKind } from "../../entity.js";
  5. import type { CacheConfig } from "../core/types.js";
  6. export declare class UpstashCache extends Cache {
  7. redis: Redis;
  8. protected useGlobally?: boolean | undefined;
  9. static readonly [entityKind]: string;
  10. /**
  11. * Prefix for sets which denote the composite table names for each unique table
  12. *
  13. * Example: In the composite table set of "table1", you may find
  14. * `${compositeTablePrefix}table1,table2` and `${compositeTablePrefix}table1,table3`
  15. */
  16. private static compositeTableSetPrefix;
  17. /**
  18. * Prefix for hashes which map hash or tags to cache values
  19. */
  20. private static compositeTablePrefix;
  21. /**
  22. * Key which holds the mapping of tags to composite table names
  23. *
  24. * Using this tagsMapKey, you can find the composite table name for a given tag
  25. * and get the cache value for that tag:
  26. *
  27. * ```ts
  28. * const compositeTable = redis.hget(tagsMapKey, 'tag1')
  29. * console.log(compositeTable) // `${compositeTablePrefix}table1,table2`
  30. *
  31. * const cachevalue = redis.hget(compositeTable, 'tag1')
  32. */
  33. private static tagsMapKey;
  34. /**
  35. * Queries whose auto invalidation is false aren't stored in their respective
  36. * composite table hashes because those hashes are deleted when a mutation
  37. * occurs on related tables.
  38. *
  39. * Instead, they are stored in a separate hash with the prefix
  40. * `__nonAutoInvalidate__` to prevent them from being deleted when a mutation
  41. */
  42. private static nonAutoInvalidateTablePrefix;
  43. private luaScripts;
  44. private internalConfig;
  45. constructor(redis: Redis, config?: CacheConfig, useGlobally?: boolean | undefined);
  46. strategy(): "all" | "explicit";
  47. private toInternalConfig;
  48. get(key: string, tables: string[], isTag?: boolean, isAutoInvalidate?: boolean): Promise<any[] | undefined>;
  49. put(key: string, response: any, tables: string[], isTag?: boolean, config?: CacheConfig): Promise<void>;
  50. onMutate(params: MutationOption): Promise<void>;
  51. private addTablePrefix;
  52. private getCompositeKey;
  53. }
  54. export declare function upstashCache({ url, token, config, global }: {
  55. url: string;
  56. token: string;
  57. config?: CacheConfig;
  58. global?: boolean;
  59. }): UpstashCache;