Vercel's Data cache not working
Answered
West African Lion posted this in #help-forum
West African LionOP
I am using
I am running into an issue where the caching doesn't work AT ALL once I deploy to Vercel.
Locally, the caching work perfectly, but on vercel it's missing the cache every single time.
I started out using
Local Logs:
Vercel Logs (had a hard time just copying the console.logs):
unstable_cache.I am running into an issue where the caching doesn't work AT ALL once I deploy to Vercel.
Locally, the caching work perfectly, but on vercel it's missing the cache every single time.
I started out using
unstable_cache initially but switched to nextjs-better-unstable-cache as the DX is poor for the current unstable_cache. The same issue occures using either unstable_cache directly or the wrapper library.Local Logs:
Data Cache - Get All Dealers HIT 0.0533s
Memoization - Get All Dealers HIT 0.0601s
Data Cache - Get All Dealers HIT 0.0164s
Memoization - Get All Dealers HIT 0.0176s
Data Cache - Get All Dealers HIT 0.0101s
Memoization - Get All Dealers HIT 0.0158s
Data Cache - Get All Dealers HIT 0.00245s
Memoization - Get All Dealers HIT 0.00296s
Data Cache - Get All Dealers HIT 0.00466s
Memoization - Get All Dealers HIT 0.0100sVercel Logs (had a hard time just copying the console.logs):
Memoization Get All Dealers HIT 0.715s
Data Cache Get All Dealers MISS 0.715s on-demand revalidation
missing getAllDealers
Memoization Get All Dealers HIT 0.329s
Data Cache Get All Dealers MISS 0.329s on-demand revalidation
missing getAllDealers
Memoization - Get All Dealers HIT 0.246s
Data Cache Get All Dealers MISS 0.245s on-demand revalidation
missing getAllDealers
Memoization Get All Dealers HIT 0.628s
Data Cache Get All Dealers MISS 0.628s on-demand revalidation
missing getAllDealers
Memoization
-
Get All Dealers HIT 0.332s
Data Cache - Get All Dealers MISS 0.331s on-demand revalidation
missing getAllDealers
Memoization Get All Dealers HIT 0.741s
Data Cache Get All Dealers MISS 0.736s on-demand revalidation
missing getAllDealers
Memoization
-
Get All Dealers HIT 0.336s
Data Cache
-
Get All Dealers MISS 0.336s on-demand revalidationAnswered by West African Lion
Ok I ugraded to 14.04, and it looks like it's resolved now:
4 Replies
West African LionOP
Function in question
My revalidateTime/duration:
import { db } from "../db"
import { memoize } from "nextjs-better-unstable-cache"
export const getAllDealers = memoize(
async () => {
console.log("missing getAllDealers")
const data = await db.dealers.findMany({
where: { active: 1, consumer_site_enabled: 1 },
include: {
_count: {
select: {
dealer_reviews: {
where: {
rating: 5,
},
},
},
},
},
})
return data
},
{
additionalCacheKey: ["get-all-dealers"],
persist: true,
duration: SiteConfig.cache.revalidateTime,
revalidateTags: ["get-all-dealers"],
log: ["dedupe", "datacache", "verbose"],
logid: "Get All Dealers",
}
)My revalidateTime/duration:
revalidateTime: 60 * 60 * 24 * 30 * 1000, (30d)My package versions:
"next": "^14.0.2",
"nextjs-better-unstable-cache": "^1.0.0",
"next": "^14.0.2",
"nextjs-better-unstable-cache": "^1.0.0",
I assume it's related to this too? https://github.com/vercel/next.js/issues/57978
West African LionOP
Ok I ugraded to 14.04, and it looks like it's resolved now:
Answer