Skip to content

Commit 373547b

Browse files
author
Nicolas Dorseuil
committed
review fix
1 parent f60141f commit 373547b

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

.changeset/slow-walls-allow.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
"@opennextjs/aws": minor
33
---
44

5-
Add an option to keep the data cache persistent between deployments
5+
Add an option to keep the data cache persistent between deployments.
6+
7+
BREAKING CHANGE: Incremental cache keys are now an object of type `CacheKey` instead of a string. The new type includes properties like `baseKey`, `buildId`, and `cacheType`. Build_id is automatically provided according to the cache type and the `dangerous.persistentDataCache` option. Up to the Incremental Cache implementation to use it as they see fit.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ export default class Cache {
5555

5656
const softTags = typeof options === "object" ? options.softTags : [];
5757
const tags = typeof options === "object" ? options.tags : [];
58-
const isDataCache = isFetchCache(options);
59-
return isDataCache
58+
return isFetchCache(options)
6059
? this.getFetchCache(baseKey, softTags, tags)
6160
: this.getIncrementalCache(baseKey);
6261
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ComposableCacheEntry, ComposableCacheHandler } from "types/cache";
22
import type { CacheKey } from "types/overrides";
33
import { writeTags } from "utils/cache";
44
import { fromReadableStream, toReadableStream } from "utils/stream";
5-
import { debug } from "./logger";
5+
import { debug, warn } from "./logger";
66

77
const pendingWritePromiseMap = new Map<string, Promise<ComposableCacheEntry>>();
88
/**
@@ -22,7 +22,7 @@ function getComposableCacheKey(key: string): CacheKey<"composable"> {
2222
baseKey: JSON.stringify(rest),
2323
} as CacheKey<"composable">;
2424
} catch (e) {
25-
debug("Error while parsing composable cache key", e);
25+
warn("Error while parsing composable cache key", e);
2626
// If we fail to parse the key, we just return it as is
2727
// This is not ideal, but we don't want to crash the application
2828
return {

packages/open-next/src/overrides/incrementalCache/s3-lite.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ const awsFetch = async (key: string, options: RequestInit) => {
3333
};
3434

3535
function buildS3Key(key: CacheKey) {
36-
const { CACHE_BUCKET_KEY_PREFIX } = process.env;
3736
return path.posix.join(
38-
CACHE_BUCKET_KEY_PREFIX ?? "",
37+
process.env.CACHE_BUCKET_KEY_PREFIX ?? "",
3938
key.cacheType === "fetch" ? "__fetch" : "",
4039
key.cacheType === "fetch"
4140
? key.baseKey

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ export type CacheValue<CacheType extends CacheEntryType> =
117117
export type CacheKey<CacheType extends CacheEntryType = CacheEntryType> = {
118118
cacheType: CacheType;
119119
buildId: CacheType extends "cache" ? string : string | undefined;
120+
/**
121+
* The base key is the main identifier for the cache entry.
122+
* It never depends on the build ID, and is used to identify the cache entry.
123+
*/
120124
baseKey: string;
121125
};
122126

0 commit comments

Comments
 (0)