Skip to content

Commit 6a5a217

Browse files
committed
review fix
1 parent 55ecac0 commit 6a5a217

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

.changeset/grumpy-dingos-pretend.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,31 @@
33
---
44

55
Bump aws to 3.6.0
6+
7+
Introduce support for the composable cache
8+
9+
BREAKING CHANGE: The interface for the Incremental cache has changed. The new interface use a Cache type instead of a boolean to distinguish between the different types of caches. It also includes a new Cache type for the composable cache. The new interface is as follows:
10+
11+
```ts
12+
export type CacheEntryType = "cache" | "fetch" | "composable";
13+
14+
export type IncrementalCache = {
15+
get<CacheType extends CacheEntryType = "cache">(
16+
key: string,
17+
cacheType?: CacheType,
18+
): Promise<WithLastModified<CacheValue<CacheType>> | null>;
19+
set<CacheType extends CacheEntryType = "cache">(
20+
key: string,
21+
value: CacheValue<CacheType>,
22+
isFetch?: CacheType,
23+
): Promise<void>;
24+
delete(key: string): Promise<void>;
25+
name: string;
26+
};
27+
```
28+
29+
NextModeTagCache also get a new function `getLastRevalidated` used for the composable cache:
30+
31+
```ts
32+
getLastRevalidated(tags: string[]): Promise<number>;
33+
```

packages/cloudflare/src/api/durable-objects/sharded-tag-cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export class DOShardedTagCache extends DurableObject<CloudflareEnv> {
1515
try {
1616
const result = this.sql
1717
.exec(
18-
`SELECT revalidatedAt FROM revalidations WHERE tag IN (${tags.map(() => "?").join(", ")}) ORDER BY revalidatedAt DESC LIMIT 1`,
18+
`SELECT MAX(revalidatedAt) AS time FROM revalidations WHERE tag IN (${tags.map(() => "?").join(", ")})`,
1919
...tags
2020
)
2121
.toArray();
2222
if (result.length === 0) return 0;
2323
// We only care about the most recent revalidation
24-
return result[0]?.revalidatedAt as number;
24+
return result[0]?.time as number;
2525
} catch (e) {
2626
console.error(e);
2727
// By default we don't want to crash here, so we return 0

packages/cloudflare/src/api/overrides/tag-cache/d1-next-tag-cache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export class D1NextModeTagCache implements NextModeTagCache {
1919
try {
2020
const result = await db
2121
.prepare(
22-
`SELECT revalidatedAt FROM revalidations WHERE tag IN (${tags.map(() => "?").join(", ")}) ORDER BY revalidatedAt DESC LIMIT 1`
22+
`SELECT MAX(revalidatedAt) AS time FROM revalidations WHERE tag IN (${tags.map(() => "?").join(", ")})`
2323
)
2424
.run();
2525

2626
if (result.results.length === 0) return 0;
2727
// We only care about the most recent revalidation
28-
return (result.results[0]?.revalidatedAt ?? 0) as number;
28+
return (result.results[0]?.time ?? 0) as number;
2929
} catch (e) {
3030
error(e);
3131
// By default we don't want to crash here, so we return false

packages/cloudflare/src/cli/build/patches/investigated/patch-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ CacheHandler = require('${normalizePath(cacheFile)}').default;
3434
export async function patchComposableCache(code: string, buildOpts: BuildOptions): Promise<string> {
3535
const { outputDir } = buildOpts;
3636

37-
// TODO: switch to cache.mjs
37+
// TODO: switch to mjs
3838
const outputPath = path.join(outputDir, "server-functions/default");
3939
const cacheFile = path.join(outputPath, getPackagePath(buildOpts), "composable-cache.cjs");
4040
//TODO: Do we want to move this to the new CodePatcher ?

0 commit comments

Comments
 (0)