next.js 放大缓存的AppSync结果

dly7yett  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(127)

我使用AWS Amplify Hosting建立了一个网站。前端是NextJS。我正在使用Amplify后端中的API类别,这反过来又使用AWS App Sync和DynamoDB。AppSync API中缓存设置为无。
我使用NextJS,因为我需要支持一些服务器端渲染(不同的功能/主题)。我在getServerSideProps()中调用API.query操作时,不知何故,数据被缓存了,我无法清除该高速缓存。
使用放大工作室(网站),我导航到内容部分,并删除记录。即使在几天之后,我删除的记录仍然会被我的API.query调用返回。我已经重新部署了build,更新了cache-control header,但还是遇到了同样的问题。
我不知道缓存在哪里发生。如果是在CloudFront,我该如何管理它?我没有访问CloudFront分发版的权限;放大隐藏了这一点。
以下是我正在打的电话:

const clientReviewsQueryResults = await (
        API.graphql({
            query: listClientReviewModels,
            authMode: 'API_KEY',
            variables: { limit: 10, filter: reviewFilter}
        })
    );

下面是我的NextJS配置文件:

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
}
const withBundleAnalyzer = require("@next/bundle-analyzer")({
  enabled: process.env.ANALYZE === "true",
});

module.exports = withBundleAnalyzer({
  ...nextConfig,
  async redirects() {
    return [
      {
        source: '/blog',
        destination: '/',
        permanent: true,
      },
      {
        source: '/contact',
        destination: '/',
        permanent: true,
      },
    ]
  },
})

下面是我得到的HTTP响应头:

回复

:status: 200
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Tue, 13 Jun 2023 14:25:53 GMT
Server: CloudFront
Vary: Accept-Encoding
Via: 1.1 9adef5b1c5fc9ca80d6f4f8d19e103a2.cloudfront.net (CloudFront)
x-amz-cf-id: N35s80oU9t24Tq-gfsywrlMfahxARl_kJKBK58PBjoU4c8Fytu6Bkw==
x-amz-cf-pop: SEA19-C3
x-cache: Miss from cloudfront
x-powered-by: Next.js

总之-我希望在使用API.query({...})时能够不缓存对后端(API/AppSync/等)的调用

iyr7buue

iyr7buue1#

我知道是怎么回事了。当我在Amplify控制台的Content部分中删除一条记录时,它实际上并没有删除底层DynamoDB表中的数据。相反,它将“_deleted”字段设置为true,并将记录上的ttl设置为30天。Amplify控制台忽略记录,但是API函数不会忽略它。此外,_deleted字段未在GraphQL模式中定义,因此该字段不能在过滤器表达式中使用。

相关问题