diff --git a/next.config.js b/next.config.js index 5ebc6612..9ebf4616 100644 --- a/next.config.js +++ b/next.config.js @@ -10,21 +10,10 @@ const withPWA = require("@ducanh2912/next-pwa").default({ disable: process.env.NODE_ENV === "development", dest: "public", publicExcludes: ["*"], - buildExcludes: [ - /\.map$/, - /^manifest.*\.js$/, - /\/chunks\/app\/dashboard/, - /\/chunks\/app\/\(home\)/, - ], + buildExcludes: [/\.map$/, /^manifest.*\.js$/, /\/chunks\/app\/dashboard/], extendDefaultRuntimeCaching: true, workboxOptions: { runtimeCaching: [ - { - urlPattern: ({ request }) => { - return request.headers.get("x-middleware-prefetch") - }, - handler: "NetworkOnly", - }, { urlPattern: ({ url }) => { return /\/ipfs\/([^/?#]+)$/.test(url.toString()) @@ -33,7 +22,7 @@ const withPWA = require("@ducanh2912/next-pwa").default({ options: { cacheName: "next-ipfs", expiration: { - maxEntries: 64, + maxEntries: 200, maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days }, cacheableResponse: { @@ -48,7 +37,7 @@ const withPWA = require("@ducanh2912/next-pwa").default({ options: { cacheName: "next-ipfs", expiration: { - maxEntries: 64, + maxEntries: 200, maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days }, }, diff --git a/src/lib/redis.server.ts b/src/lib/redis.server.ts index 022892e1..e2de0db7 100644 --- a/src/lib/redis.server.ts +++ b/src/lib/redis.server.ts @@ -1,6 +1,6 @@ import Redis from "ioredis" -import { REDIS_EXPIRE, REDIS_URL } from "~/lib/env.server" +import { REDIS_EXPIRE, REDIS_REFRESH, REDIS_URL } from "~/lib/env.server" if (!REDIS_URL) { console.error("REDIS_URL not set") @@ -52,16 +52,18 @@ export async function cacheGet(options: { const cacheValue = await redis.get(redisKey) if (cacheValue && cacheValue !== "undefined" && cacheValue !== "null") { if (!options.noUpdate) { - options.getValueFun().then((value) => { - if (value) { - redis.set( - redisKey, - JSON.stringify(value), - "EX", - options.expireTime || REDIS_EXPIRE, - ) - } - }) + setTimeout(() => { + options.getValueFun().then((value) => { + if (value) { + redis.set( + redisKey, + JSON.stringify(value), + "EX", + options.expireTime || REDIS_EXPIRE, + ) + } + }) + }, Math.random() * REDIS_REFRESH) } return JSON.parse(cacheValue) } else {