diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 79d99600524..442ac4b5bb9 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -243,6 +243,8 @@ LFS_CONTENT_PATH = data/lfs LFS_JWT_SECRET = ; LFS authentication validity period (in time.Duration), pushes taking longer than this may fail. LFS_HTTP_AUTH_EXPIRY = 20m +; Static resources, includes resources on custom/, public/ and all uploaded avatars web browser cache time, default is 6h +STATIC_CACHE_TIME = 6h ; Define allowed algorithms and their minimum key length (use -1 to disable a type) [ssh.minimum_key_sizes] diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 100bb229ee6..6313e705d4c 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -140,6 +140,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `CERT_FILE`: **custom/https/cert.pem**: Cert file path used for HTTPS. - `KEY_FILE`: **custom/https/key.pem**: Key file path used for HTTPS. - `STATIC_ROOT_PATH`: **./**: Upper level of template and static files path. +- `STATIC_CACHE_TIME`: **6h**: Web browser cache time for static resources on `custom/`, `public/` and all uploaded avatars. - `ENABLE_GZIP`: **false**: Enables application-level GZIP support. - `LANDING_PAGE`: **home**: Landing page for unauthenticated users \[home, explore\]. - `LFS_START_SERVER`: **false**: Enables git-lfs support. diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index ab73e2059ec..a0e33c63702 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -65,6 +65,7 @@ menu: - `CERT_FILE`: 启用HTTPS的证书文件。 - `KEY_FILE`: 启用HTTPS的密钥文件。 - `STATIC_ROOT_PATH`: 存放模板和静态文件的根目录,默认是 Gitea 的根目录。 +- `STATIC_CACHE_TIME`: **6h**: 静态资源文件,包括 `custom/`, `public/` 和所有上传的头像的浏览器缓存时间。 - `ENABLE_GZIP`: 启用应用级别的 GZIP 压缩。 - `LANDING_PAGE`: 未登录用户的默认页面,可选 `home` 或 `explore`。 - `LFS_START_SERVER`: 是否启用 git-lfs 支持. 可以为 `true` 或 `false`, 默认是 `false`。 diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 278ed4b107e..629a89766f7 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -87,6 +87,7 @@ var ( CertFile string KeyFile string StaticRootPath string + StaticCacheTime time.Duration EnableGzip bool LandingPageURL LandingPage UnixSocketPermission uint32 @@ -607,6 +608,7 @@ func NewContext() { OfflineMode = sec.Key("OFFLINE_MODE").MustBool() DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool() StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(AppWorkPath) + StaticCacheTime = sec.Key("STATIC_CACHE_TIME").MustDuration(6 * time.Hour) AppDataPath = sec.Key("APP_DATA_PATH").MustString(path.Join(AppWorkPath, "data")) EnableGzip = sec.Key("ENABLE_GZIP").MustBool() EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 8dfcdb9c9b6..0db0af43f0b 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -139,14 +139,14 @@ func NewMacaron() *macaron.Macaron { m.Use(public.Custom( &public.Options{ SkipLogging: setting.DisableRouterLog, - ExpiresAfter: time.Hour * 6, + ExpiresAfter: setting.StaticCacheTime, }, )) m.Use(public.Static( &public.Options{ Directory: path.Join(setting.StaticRootPath, "public"), SkipLogging: setting.DisableRouterLog, - ExpiresAfter: time.Hour * 6, + ExpiresAfter: setting.StaticCacheTime, }, )) m.Use(public.StaticHandler( @@ -154,7 +154,7 @@ func NewMacaron() *macaron.Macaron { &public.Options{ Prefix: "avatars", SkipLogging: setting.DisableRouterLog, - ExpiresAfter: time.Hour * 6, + ExpiresAfter: setting.StaticCacheTime, }, )) m.Use(public.StaticHandler( @@ -162,7 +162,7 @@ func NewMacaron() *macaron.Macaron { &public.Options{ Prefix: "repo-avatars", SkipLogging: setting.DisableRouterLog, - ExpiresAfter: time.Hour * 6, + ExpiresAfter: setting.StaticCacheTime, }, ))