Skip to content

Commit 6ea85fc

Browse files
committed
refactor: drop global disableDynamoDBCache and disableIncrementalCache
1 parent 7c9f274 commit 6ea85fc

File tree

5 files changed

+29
-32
lines changed

5 files changed

+29
-32
lines changed

packages/open-next/src/adapters/cache.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default class Cache {
116116
kind?: "FETCH";
117117
},
118118
) {
119-
if (globalThis.disableIncrementalCache) {
119+
if (globalThis.openNextConfig.dangerous?.disableIncrementalCache) {
120120
return null;
121121
}
122122

@@ -260,7 +260,7 @@ export default class Cache {
260260
data?: IncrementalCacheValue,
261261
ctx?: IncrementalCacheContext,
262262
): Promise<void> {
263-
if (globalThis.disableIncrementalCache) {
263+
if (globalThis.openNextConfig.dangerous?.disableIncrementalCache) {
264264
return;
265265
}
266266
// This one might not even be necessary anymore
@@ -396,7 +396,8 @@ export default class Cache {
396396
}
397397

398398
public async revalidateTag(tags: string | string[]) {
399-
if (globalThis.disableDynamoDBCache || globalThis.disableIncrementalCache) {
399+
const config = globalThis.openNextConfig.dangerous;
400+
if (config?.disableTagCache || config?.disableIncrementalCache) {
400401
return;
401402
}
402403
try {

packages/open-next/src/build/compileCache.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,7 @@ export function compileCache(
2828
target: ["node18"],
2929
format,
3030
banner: {
31-
js: [
32-
`globalThis.disableIncrementalCache = ${
33-
config.dangerous?.disableIncrementalCache ?? false
34-
};`,
35-
`globalThis.disableDynamoDBCache = ${
36-
config.dangerous?.disableTagCache ?? false
37-
};`,
38-
`globalThis.isNextAfter15 = ${isAfter15};`,
39-
].join(""),
31+
js: `globalThis.isNextAfter15 = ${isAfter15};`,
4032
},
4133
},
4234
options,

packages/open-next/src/overrides/tagCache/dynamodb-lite.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ function buildDynamoObject(path: string, tags: string, revalidatedAt?: number) {
6868
const tagCache: TagCache = {
6969
async getByPath(path) {
7070
try {
71-
if (globalThis.disableDynamoDBCache) return [];
71+
if (globalThis.openNextConfig.dangerous?.disableTagCache) {
72+
return [];
73+
}
7274
const { CACHE_DYNAMO_TABLE, NEXT_BUILD_ID } = process.env;
7375
const result = await awsFetch(
7476
JSON.stringify({
@@ -101,7 +103,9 @@ const tagCache: TagCache = {
101103
},
102104
async getByTag(tag) {
103105
try {
104-
if (globalThis.disableDynamoDBCache) return [];
106+
if (globalThis.openNextConfig.dangerous?.disableTagCache) {
107+
return [];
108+
}
105109
const { CACHE_DYNAMO_TABLE, NEXT_BUILD_ID } = process.env;
106110
const result = await awsFetch(
107111
JSON.stringify({
@@ -133,7 +137,9 @@ const tagCache: TagCache = {
133137
},
134138
async getLastModified(key, lastModified) {
135139
try {
136-
if (globalThis.disableDynamoDBCache) return lastModified ?? Date.now();
140+
if (globalThis.openNextConfig.dangerous?.disableTagCache) {
141+
return lastModified ?? Date.now();
142+
}
137143
const { CACHE_DYNAMO_TABLE } = process.env;
138144
const result = await awsFetch(
139145
JSON.stringify({
@@ -168,7 +174,9 @@ const tagCache: TagCache = {
168174
async writeTags(tags) {
169175
try {
170176
const { CACHE_DYNAMO_TABLE } = process.env;
171-
if (globalThis.disableDynamoDBCache) return;
177+
if (globalThis.openNextConfig.dangerous?.disableTagCache) {
178+
return;
179+
}
172180
const dataChunks = chunk(tags, MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT).map(
173181
(Items) => ({
174182
RequestItems: {

packages/open-next/src/overrides/tagCache/dynamodb.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ function buildDynamoObject(path: string, tags: string, revalidatedAt?: number) {
4444
const tagCache: TagCache = {
4545
async getByPath(path) {
4646
try {
47-
if (globalThis.disableDynamoDBCache) return [];
47+
if (globalThis.openNextConfig.dangerous?.disableTagCache) {
48+
return [];
49+
}
4850
const result = await dynamoClient.send(
4951
new QueryCommand({
5052
TableName: CACHE_DYNAMO_TABLE,
@@ -69,7 +71,9 @@ const tagCache: TagCache = {
6971
},
7072
async getByTag(tag) {
7173
try {
72-
if (globalThis.disableDynamoDBCache) return [];
74+
if (globalThis.openNextConfig.dangerous?.disableTagCache) {
75+
return [];
76+
}
7377
const { Items } = await dynamoClient.send(
7478
new QueryCommand({
7579
TableName: CACHE_DYNAMO_TABLE,
@@ -95,7 +99,9 @@ const tagCache: TagCache = {
9599
},
96100
async getLastModified(key, lastModified) {
97101
try {
98-
if (globalThis.disableDynamoDBCache) return lastModified ?? Date.now();
102+
if (globalThis.openNextConfig.dangerous?.disableTagCache) {
103+
return lastModified ?? Date.now();
104+
}
99105
const result = await dynamoClient.send(
100106
new QueryCommand({
101107
TableName: CACHE_DYNAMO_TABLE,
@@ -123,7 +129,9 @@ const tagCache: TagCache = {
123129
},
124130
async writeTags(tags) {
125131
try {
126-
if (globalThis.disableDynamoDBCache) return;
132+
if (globalThis.openNextConfig.dangerous?.disableTagCache) {
133+
return;
134+
}
127135
const dataChunks = chunk(tags, MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT).map(
128136
(Items) => ({
129137
RequestItems: {

packages/open-next/src/types/global.ts

-12
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ declare global {
7373
* Defined in `createMainHandler` or in `adapter/middleware.ts`.
7474
*/
7575
var tagCache: TagCache;
76-
/**
77-
* A boolean that indicates if the DynamoDB cache is disabled.
78-
* TODO: Remove this, we already have access to the config file
79-
* Defined in esbuild banner for the cache adapter.
80-
*/
81-
var disableDynamoDBCache: boolean;
82-
/**
83-
* A boolean that indicates if the incremental cache is disabled.
84-
* TODO: Remove this, we already have access to the config file
85-
* Defined in esbuild banner for the cache adapter.
86-
*/
87-
var disableIncrementalCache: boolean;
8876

8977
/**
9078
* An object that contains the last modified time of the pages.

0 commit comments

Comments
 (0)