You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changelog nor upgrade guide did not mention that cache handler now sends page data as buffer instead of a string. Which seems like a trivial change for in-memory caches, it actually broke our Redis integration.
To make our upgrade from 14 -> 15 compatible with our cache handler we had to add a decorator that parses data.value.body from Buffer to String and back.
function createNext15BufferResolverHandler(handler) {
return {
async get(key, ctx) {
const hit = await handler.get(key, ctx);
if (hit?.value?.body) {
return {
...hit,
value: { ...hit.value, body: Buffer.from(hit.value.body, "utf-8") }, // Converts string from Redis handler to Buffer
};
}
return hit;
},
async set(key, data) {
try {
await handler.set(
key,
data?.value?.body
? {
...data,
value: {
...data.value,
body: data.value.body.toString(), // Converts Buffer from to save it as string in Redis
},
}
: data,
);
} catch (e) {
console.error(e);
}
},
async revalidateTag(tag) {
await handler.revalidateTag(tag);
},
async delete(key) {
await handler.delete(key);
},
};
}
I am not even sure if this is a missing documentation or bug. What is expected behaviour? Should it be Buffer in Next15 or is it unintentional change? If this is intentional, then please add a breaking change notice as this was not included in the changelog or upgrade guide.
Is there any context that might help us understand?
Example cache handler from Next documentation.
const cache = new Map()
module.exports = class CacheHandler {
constructor(options) {
this.options = options
}
async get(key) {
// This could be stored anywhere, like durable storage
return cache.get(key)
}
async set(key, data, ctx) {
// This could be stored anywhere, like durable storage
cache.set(key, {
value: data,
lastModified: Date.now(),
tags: ctx.tags,
})
}
async revalidateTag(tags) {
// tags is either a string or an array of strings
tags = [tags].flat()
// Iterate over all entries in the cache
for (let [key, value] of cache) {
// If the value's tags include the specified tag, delete this entry
if (value.tags.some((tag) => tags.includes(tag))) {
cache.delete(key)
}
}
}
// If you want to have temporary in memory cache for a single request that is reset
// before the next request you can leverage this method
resetRequestCache() {}
}
Does the docs page already exist? Please link to it.
No response
The text was updated successfully, but these errors were encountered:
What is the documentation issue?
Changelog nor upgrade guide did not mention that cache handler now sends page data as buffer instead of a string. Which seems like a trivial change for in-memory caches, it actually broke our Redis integration.
To make our upgrade from 14 -> 15 compatible with our cache handler we had to add a decorator that parses
data.value.body
from Buffer to String and back.I am not even sure if this is a missing documentation or bug. What is expected behaviour? Should it be Buffer in Next15 or is it unintentional change? If this is intentional, then please add a breaking change notice as this was not included in the changelog or upgrade guide.
Is there any context that might help us understand?
Example cache handler from Next documentation.
Does the docs page already exist? Please link to it.
No response
The text was updated successfully, but these errors were encountered: