cache.ts 710 B

123456789101112131415161718192021222324252627282930
  1. import type { Cache as ACDCache } from "async-cache-dedupe";
  2. import { createCache } from "async-cache-dedupe";
  3. import { stringify, parse } from "superjson";
  4. import { getRedis } from "./config/server";
  5. const transformer = {
  6. serialize: stringify,
  7. deserialize: parse,
  8. };
  9. export const DEFAULT_CACHE_TTL = 86_400; // 24 hours
  10. export const DEFAULT_CACHE_STALE = 86_400; // 24 hours
  11. export const redisCache: ACDCache = createCache({
  12. transformer,
  13. stale: DEFAULT_CACHE_STALE,
  14. ttl: DEFAULT_CACHE_TTL,
  15. storage: {
  16. type: "redis",
  17. options: {
  18. client: getRedis(),
  19. },
  20. },
  21. });
  22. export const memoryOnlyCache: ACDCache = createCache({
  23. ttl: DEFAULT_CACHE_TTL,
  24. stale: DEFAULT_CACHE_STALE,
  25. });