Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/cache-handler/src/handlers/memory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe("MemoryCacheHandler", () => {
describe("TTL and expiration", () => {
test("should expire entries based on revalidate time", async () => {
const value: CacheValue = {
kind: "PAGE",
kind: "PAGES",
html: "<html>test</html>",
pageData: { test: true },
};
Expand Down Expand Up @@ -197,7 +197,7 @@ describe("MemoryCacheHandler", () => {
const handlerWithTTL = createMemoryCacheHandler({ defaultTTL: 1 });

const value: CacheValue = {
kind: "PAGE",
kind: "PAGES",
html: "<html>test</html>",
pageData: { test: true },
};
Expand Down Expand Up @@ -244,7 +244,7 @@ describe("MemoryCacheHandler", () => {

test("should handle implicit tags via meta parameter", async () => {
const value: CacheValue = {
kind: "PAGE",
kind: "PAGES",
html: "<html>test</html>",
pageData: { test: true },
};
Expand Down
5 changes: 3 additions & 2 deletions packages/cache-handler/src/handlers/memory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isImplicitTag } from "../helpers/is-implicit-tag.js";
import { calculateLifespan, isExpired } from "../helpers/lifespan.js";
import { jsonReplacer } from "../helpers/serialization.js";
import type {
CacheHandler,
CacheHandlerContext,
Expand Down Expand Up @@ -105,8 +106,8 @@ export class MemoryCacheHandler implements CacheHandler {
}

async set(key: string, value: CacheValue, context?: CacheHandlerContext): Promise<void> {
// Calculate size of the entry
const size = JSON.stringify(value).length;
// Calculate size of the entry (use replacer to account for Map/Buffer)
const size = JSON.stringify(value, jsonReplacer).length;

// Check if entry exceeds max size
if (size > this.maxItemSizeBytes) {
Expand Down
Loading
Loading