Skip to content

Commit f567760

Browse files
committed
incorporate suggestions
1 parent 649f620 commit f567760

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

packages/cloudflare/src/api/r2-incremental-cache.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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 { IncrementalCacheEntry } from "./internal/incremental-cache.js";
76

87
/**
98
* An instance of the Incremental Cache that uses an R2 bucket (`NEXT_CACHE_R2_BUCKET`) as it's
@@ -31,7 +30,10 @@ class R2IncrementalCache implements IncrementalCache {
3130
const r2Object = await r2.get(this.getR2Key(key, isFetch));
3231
if (!r2Object) return null;
3332

34-
return r2Object.json();
33+
return {
34+
value: await r2Object.json(),
35+
lastModified: r2Object.uploaded.getTime(),
36+
};
3537
} catch (e) {
3638
error("Failed to get from cache", e);
3739
return null;
@@ -49,14 +51,7 @@ class R2IncrementalCache implements IncrementalCache {
4951
debug(`Set ${key}`);
5052

5153
try {
52-
const entry: IncrementalCacheEntry<IsFetch> = {
53-
value,
54-
// Note: `Date.now()` returns the time of the last IO rather than the actual time.
55-
// See https://developers.cloudflare.com/workers/reference/security-model/
56-
lastModified: Date.now(),
57-
};
58-
59-
await r2.put(this.getR2Key(key, isFetch), JSON.stringify(entry));
54+
await r2.put(this.getR2Key(key, isFetch), JSON.stringify(value));
6055
} catch (e) {
6156
error("Failed to set to cache", e);
6257
}

packages/cloudflare/src/api/regional-cache.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,25 @@ class RegionalCache implements IncrementalCache {
7272
isFetch?: IsFetch
7373
): Promise<void> {
7474
try {
75-
await Promise.all([
76-
this.store.set(key, value, isFetch),
77-
this.putToCache(this.getCacheKey(key, isFetch), {
78-
value,
79-
// Note: `Date.now()` returns the time of the last IO rather than the actual time.
80-
// See https://developers.cloudflare.com/workers/reference/security-model/
81-
lastModified: Date.now(),
82-
}),
83-
]);
75+
await this.store.set(key, value, isFetch);
76+
77+
await this.putToCache(this.getCacheKey(key, isFetch), {
78+
value,
79+
// Note: `Date.now()` returns the time of the last IO rather than the actual time.
80+
// See https://developers.cloudflare.com/workers/reference/security-model/
81+
lastModified: Date.now(),
82+
});
8483
} catch (e) {
8584
error(`Failed to get from regional cache`, e);
8685
}
8786
}
8887

8988
async delete(key: string): Promise<void> {
9089
try {
90+
await this.store.delete(key);
91+
9192
const cache = await this.getCacheInstance();
92-
await Promise.all([this.store.delete(key), cache.delete(this.getCacheKey(key))]);
93+
await cache.delete(this.getCacheKey(key));
9394
} catch (e) {
9495
error("Failed to delete from regional cache", e);
9596
}

packages/cloudflare/src/cli/build/utils/populate-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function populateCache(opts: BuildOptions, config: OpenNextConfig,
9898
break;
9999
}
100100
default:
101-
logger.info("INcremental cache does not need populating");
101+
logger.info("Incremental cache does not need populating");
102102
}
103103
}
104104

0 commit comments

Comments
 (0)