Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set cache-control default value to "public, max-age=300" #462

Merged
merged 2 commits into from
May 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export default (appInfo: EggAppConfig) => {
enableWebAuthn: false,
// http response cache control header
enableCDN: false,
// if you are using CDN, can set it to 'max-age=0, s-maxage=120, must-revalidate'
// it meaning cache 10s on CDN server and no cache on client side.
cdnCacheControlHeader: 'max-age=0, s-maxage=120, must-revalidate',
// if you are using CDN, can override it
// it meaning cache 300s on CDN server and client side.
cdnCacheControlHeader: 'public, max-age=300',
// if you are using CDN, can set it to 'Accept, Accept-Encoding'
cdnVaryHeader: 'Accept, Accept-Encoding',
// store full package version manifests data to database table(package_version_manifests), default is false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码看起来主要是在配置 Egg 应用,其中涉及到 Http 缓存控制的设置。以下是我的建议:

改进建议:

  • cdnCacheControlHeader 可以增加 CLI 配置项,让用户可以根据需要自定义缓存时间,例如 10s 或 1min 等。
  • enableCDN 建议改为 enableHttpCache 等更准确的命名。

风险提示:

  • 使用 CDN 后一定要谨慎地处理缓存时间的问题,否则可能导致 CDN 缓存错误数据。

Expand Down