Skip to content

Commit f62f538

Browse files
authored
Update caching.mdx (#496)
* Update caching.mdx * Fix formatting
1 parent 92432af commit f62f538

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

docs/pages/inner_workings/caching.mdx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@ await invalidateCloudFrontPaths(["/page/*"]);
8080
For on-demand revalidation via the [`next/cache` module](https://nextjs.org/docs/app/building-your-application/data-fetching/revalidating#using-on-demand-revalidation), if you want to retrieve the associated paths for a given tag, you can use this function:
8181

8282
```ts
83-
function getByTag(tag: string) {
83+
import { DynamoDBClient, QueryCommand } from '@aws-sdk/client-dynamodb';
84+
85+
const client = new DynamoDBClient({ region: process.env.CACHE_BUCKET_REGION });
86+
87+
async function getPaths(tag: string) {
8488
try {
85-
const { Items } = await this.dynamoClient.send(
89+
const { Items } = await client.send(
8690
new QueryCommand({
8791
TableName: process.env.CACHE_DYNAMO_TABLE,
8892
KeyConditionExpression: "#tag = :tag",
@@ -95,13 +99,13 @@ function getByTag(tag: string) {
9599
}),
96100
);
97101
return (
98-
// We need to remove the buildId from the path
99102
Items?.map(
100-
({ path: { S: key } }) => key?.replace(`${process.env.NEXT_BUILD_ID}/`, "") ?? "",
103+
(item) =>
104+
item.path?.S?.replace(`${process.env.NEXT_BUILD_ID}/`, "") ?? "",
101105
) ?? []
102106
);
103107
} catch (e) {
104-
error("Failed to get by tag", e);
108+
console.error("Failed to get by tag", e);
105109
return [];
106110
}
107111
}

0 commit comments

Comments
 (0)