Issue:
Image cache reads and writes have unexpectedly spiked from zero to around 4k per day, despite having only ~10 users daily. No recent changes were made to the codebase. The app is built with Next.js.
Request:
Looking for insights into what could cause this sudden increase in image cache activity and how to diagnose or resolve the issue.
Additional Context:
Using Next.js with next/image for image optimization.
The issue appeared without code changes.
Traffic has remained consistent at ~10 users/day.
Any suggestions on what to check or potential causes would be appreciated!
Hey @anshumanb, I’m experiencing the same problem. ~20 users, around 75 images in total and this metric exploded within a couple of hours. I set minimumCacheTTL: 2_678_400, // 31 days in my next.config.ts but it didn’t seem to work. Is there any other way to prevent this from happening?
Hi @bartekczyz, thanks for reaching out here. Did you check using the Open in Observability to see which images are causing higher requests? Maybe that helps us narrow down the scope.
Hi @anshumanb Yes I did, but there was nothing suspicious about it. In this case ~182 photos being transformed 1-3 times, but it was written to cache ~25k times I cant’t figure out the math behind it.
Your images are being transformed from about 2MB to about 1MB (see the Transformed Size).
The transformed size is then cached and billed per 8KB for once cache write unit.
So a 1MB image would incur 125 cache write units, or 22750 write units total. That is very close to the 25K units you’re seeing and the rounding error is likely that those images are over 1MB.
My suggestion is to lower the quality prop to compress those images further or adjust the width.
Ok now it makes sense, or at least math is correct now. Please update your docs and explain what a cache write actually is, I thought it’s a single image being written, turns out it’s each 8kB of every image. Well, that’s not ideal, gonna have to think of some other solution.
The docs mention the 8KB units in the definition here:
Image cache writes: The total amount of Write Units used to store the cached image in the global cache, measured in 8KB units. It is billed for every cache MISS and STALE.