Spaces:
Runtime error
Runtime error
File size: 1,293 Bytes
4782147 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import { MemoryCache } from "./memory-cache";
import { Cache } from "./cache.interface";
import { IS_DEV } from "lib/const";
import logger from "logger";
declare global {
// eslint-disable-next-line no-var
var __server__cache__: Cache | undefined;
}
const createCache = () => {
const redisUrl = process.env.REDIS_URL;
if (IS_DEV) {
logger.info("Using MemoryCache for development");
return new MemoryCache();
}
if (redisUrl) {
// logger.info("Using SafeRedisCache with automatic fallback");
// return new SafeRedisCache({
// redisUrl,
// fallbackToMemory: true,
// redisOptions: {
// retryStrategy: (times) => {
// if (times > 3) {
// logger.error("Redis connection failed after 3 retries");
// return null;
// }
// return Math.min(times * 1000, 3000);
// },
// maxRetriesPerRequest: 2,
// enableOfflineQueue: false,
// connectTimeout: 5000,
// commandTimeout: 5000,
// },
// });
}
// logger.warn("No Redis URL found, using MemoryCache");
return new MemoryCache();
};
const serverCache = globalThis.__server__cache__ || createCache();
if (IS_DEV) {
globalThis.__server__cache__ = serverCache;
}
export { serverCache };
|