Skip to main content

缓存与性能

🌐 Caching & Performance

Page summary:

通过 Cache-Control 头进行边缘缓存可以减少大型静态内容的延迟和服务器负载。

对于具有大量可缓存内容(如图片、视频和其他静态资源)的 Strapi Cloud 应用,通过 `Cache-control` header 启用 CDN(内容分发网络)缓存可以帮助提升应用性能。

🌐 For Strapi Cloud applications with large amounts of cacheable content, such as images, videos, and other static assets, enabling CDN (Content Delivery Network) caching via the `Cache-control` header can help improve application performance.

CDN 缓存可以通过几种方式帮助提高应用性能:

🌐 CDN caching can help improve application performance in a few ways:

  • 降低延迟:将频繁访问的内容缓存到更靠近终端用户的边缘服务器上,可以减少加载内容所需的时间。
  • 卸载源服务器:通过在边缘服务器上缓存内容,可以卸载源服务器,减少其负载,并使其能够专注于提供更多动态内容。
  • 应对流量骤增:通过将负载分配到多个边缘服务器来帮助应对流量骤增。这可以防止源服务器在高峰流量期间不堪重负,并确保用户体验的一致性。

Strapi Cloud 中的 Cache-Control 头

🌐 Cache-Control Header in Strapi Cloud

部署在 Strapi Cloud 上的静态网站默认包含一个 Cache-Control 头,该头在 CDN 边缘服务器上缓存 24 小时,在网页浏览器中缓存 10 秒。这是为了确保向用户提供网站的最新版本。

🌐 Static sites deployed on Strapi Cloud include, by default, a Cache-Control header set to cache for 24 hours on CDN edge servers and 10 seconds in web browsers. This is done to ensure that the latest version of the site is always served to users.

由 Strapi Cloud 提供的动态应用的响应默认不缓存。要启用缓存,你必须在应用的 HTTP 响应函数中设置 Cache-Control 头。

🌐 Responses from dynamic apps served by Strapi Cloud are not cached by default. To enable caching, you must set the Cache-Control header in the app’s HTTP response functions.

function myHandler(req, res) {
// Set the Cache-Control header to cache responses for 1 day
res.setHeader('Cache-Control', 'max-age=86400');

// Add your logic to generate the response here
}