简体   繁体   English

要从AWS CloudFront删除缓存控制标头吗?

[英]Remove Cache-Control headers from AWS CloudFront?

I'm setting Cache-Control:s-maxage=3600 from my Origin server. 我正在从我的原始服务器设置Cache-Control:s-maxage = 3600。 By this I'm instructing my AWS CloudFront to cache the content for 3600 seconds. 由此,我指示我的AWS CloudFront将内容缓存3600秒。 I have white listed some cookies and set caching based on the cookie values in CloudFront. 我在白名单中列出了一些cookie,并根据CloudFront中的cookie值设置了缓存。 This setup is working fine until there is no proxy in between the client and my CloudFront. 直到客户端和我的CloudFront之间没有代理为止,此设置才能正常工作。

If there is Proxy, It also caches a version due to s-maxage header without considering the cookie value. 如果有代理,它还会由于s-maxage标头而缓存版本,而不考虑cookie值。 Due to this my end users are seeing irrelevant versions of my web page. 因此,我的最终用户看到了与我的网页无关的版本。

Is there any way to overcome this? 有什么办法可以克服这个问题? Or I need to write a Lambda@edge function to remove this Cache-Control:s-maxage=3600 in Viewer Response? 还是我需要编写Lambda @ edge函数以在“查看器响应”中删除此Cache-Control:s-maxage = 3600?

Create a Lamda@Edge function at Viewer Response and reset the Cache-Control header. 在查看器响应处创建一个Lamda @ Edge函数,并重置Cache-Control标头。

exports.handler = (event, context, callback) => {

    /* Get response */
    const response = event.Records[0].cf.response;       

    response.headers['cache-control'] = [{
        key: 'cache-control', value: 'no-cache, no-store, must-revalidate'
    }];

    callback(null, response);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Origin Cache-Control在AWS Cloudfront上不起作用 - Origin Cache-Control not working on AWS Cloudfront 在 AWS Cloudfront 中如何添加缓存控制? - In AWS Cloudfront how to add cache-control? CloudFront是否在来自原点的错误响应(例如503)中使用Cache-Control标头? - Does CloudFront make use of Cache-Control headers in error responses (e.g. 503) from the origin? AWS Elastic Beanstalk / S3 / CloudFront缓存控制标头 - AWS Elastic Beanstalk / S3 / CloudFront Cache-Control Header 来自 AWS CloudFront 的外部 Next.js 图像的缓存控制策略对于 Google Lighthouse 效率不高 - Cache-Control policy for external Next.js Image coming from AWS CloudFront is not efficient for Google Lighthouse 为要上传到AWS S3的图像设置Expires和Cache-Control标头 - Setting Expires and Cache-Control headers for images that are being uploaded to AWS S3 如何在亚马逊云端设置 Cache-Control Header? - How to set Cache-Control Header in amazon cloudfront? 从PHP AWS SDK设置S3对象的缓存控制HTTP标头 - Set Cache-Control HTTP Header for S3 Objects from PHP AWS SDK Amazon Cloudfront Cache-Control:no-cache 标头在 24 小时后无效 - Amazon Cloudfront Cache-Control: no-cache header has no effect after 24 hours 将缓存控制元数据添加到AWS Elastic Transcoder输出 - Add Cache-Control Metadata to AWS Elastic Transcoder Output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM