Skip to content

Commit e0dbf2e

Browse files
committed
align with other inc cache changes
1 parent c86e2bc commit e0dbf2e

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

packages/cloudflare/src/api/overrides/incremental-cache/static-assets-incremental-cache.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { CacheValue, IncrementalCache, WithLastModified } from "@opennextjs
33
import { IgnorableError } from "@opennextjs/aws/utils/error.js";
44

55
import { getCloudflareContext } from "../../cloudflare-context.js";
6+
import { debugCache, FALLBACK_BUILD_ID } from "../internal.js";
67

78
export const CACHE_DIR = "cdn-cgi/_next_cache";
89

@@ -22,7 +23,7 @@ class StaticAssetsIncrementalCache implements IncrementalCache {
2223
const assets = getCloudflareContext().env.ASSETS;
2324
if (!assets) throw new IgnorableError("No Static Assets");
2425

25-
debug(`Get ${key}`);
26+
debugCache(`Get ${key}`);
2627

2728
try {
2829
const response = await assets.fetch(this.getAssetUrl(key, isFetch));
@@ -39,12 +40,16 @@ class StaticAssetsIncrementalCache implements IncrementalCache {
3940
}
4041
}
4142

42-
async set(): Promise<void> {}
43+
async set(): Promise<void> {
44+
error("Failed to set to read-only cache");
45+
}
4346

44-
async delete(): Promise<void> {}
47+
async delete(): Promise<void> {
48+
error("Failed to delete from read-only cache");
49+
}
4550

4651
protected getAssetUrl(key: string, isFetch?: boolean): string {
47-
const buildId = process.env.NEXT_BUILD_ID ?? "no-build-id";
52+
const buildId = process.env.NEXT_BUILD_ID ?? FALLBACK_BUILD_ID;
4853
const name = `${CACHE_DIR}/${buildId}/${key}.${isFetch ? "fetch" : "cache"}`.replace(/\/+/g, "/");
4954
return `http://assets.local/${name}`;
5055
}

packages/cloudflare/src/cli/commands/populate-cache.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ function populateD1TagCache(
155155
logger.info("\nSuccessfully created D1 table");
156156
}
157157

158+
function populateStaticAssetsIncrementalCache(options: BuildOptions) {
159+
logger.info("\nPopulating Workers static assets...");
160+
161+
const assets = getCacheAssetPaths(options);
162+
for (const { fsPath, destPath } of tqdm(assets)) {
163+
const outputDestPath = path.join(options.outputDir, "assets", STATIC_ASSETS_CACHE_DIR, destPath);
164+
mkdirSync(path.dirname(outputDestPath), { recursive: true });
165+
cpSync(fsPath, outputDestPath);
166+
}
167+
logger.info(`Successfully populated static assets cache with ${assets.length} assets`);
168+
}
169+
158170
export async function populateCache(
159171
options: BuildOptions,
160172
config: OpenNextConfig,
@@ -176,18 +188,9 @@ export async function populateCache(
176188
case KV_CACHE_NAME:
177189
populateKVIncrementalCache(options, populateCacheOptions);
178190
break;
179-
case STATIC_ASSETS_CACHE_NAME: {
180-
logger.info("\nPopulating Workers static assets...");
181-
182-
const assets = getCacheAssetPaths(options);
183-
for (const { fsPath, destPath } of tqdm(assets)) {
184-
const outputDestPath = path.join(options.outputDir, "assets", STATIC_ASSETS_CACHE_DIR, destPath);
185-
mkdirSync(path.dirname(outputDestPath), { recursive: true });
186-
cpSync(fsPath, outputDestPath);
187-
}
188-
logger.info(`Successfully populated static assets cache with ${assets.length} assets`);
191+
case STATIC_ASSETS_CACHE_NAME:
192+
populateStaticAssetsIncrementalCache(options);
189193
break;
190-
}
191194
default:
192195
logger.info("Incremental cache does not need populating");
193196
}

0 commit comments

Comments
 (0)