Skip to content

Commit 0be992a

Browse files
lunnyzeripath
authored andcommitted
Make static resouces web browser cache time customized on app.ini (#8442)
* make static resouces web browser cache time customized on app.ini * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md Co-Authored-By: zeripath <[email protected]> * Update custom/conf/app.ini.sample Co-Authored-By: Antoine GIRARD <[email protected]> * fix docs
1 parent b6ef539 commit 0be992a

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

custom/conf/app.ini.sample

+2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ LFS_CONTENT_PATH = data/lfs
243243
LFS_JWT_SECRET =
244244
; LFS authentication validity period (in time.Duration), pushes taking longer than this may fail.
245245
LFS_HTTP_AUTH_EXPIRY = 20m
246+
; Static resources, includes resources on custom/, public/ and all uploaded avatars web browser cache time, default is 6h
247+
STATIC_CACHE_TIME = 6h
246248

247249
; Define allowed algorithms and their minimum key length (use -1 to disable a type)
248250
[ssh.minimum_key_sizes]

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
140140
- `CERT_FILE`: **custom/https/cert.pem**: Cert file path used for HTTPS.
141141
- `KEY_FILE`: **custom/https/key.pem**: Key file path used for HTTPS.
142142
- `STATIC_ROOT_PATH`: **./**: Upper level of template and static files path.
143+
- `STATIC_CACHE_TIME`: **6h**: Web browser cache time for static resources on `custom/`, `public/` and all uploaded avatars.
143144
- `ENABLE_GZIP`: **false**: Enables application-level GZIP support.
144145
- `LANDING_PAGE`: **home**: Landing page for unauthenticated users \[home, explore\].
145146
- `LFS_START_SERVER`: **false**: Enables git-lfs support.

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ menu:
6565
- `CERT_FILE`: 启用HTTPS的证书文件。
6666
- `KEY_FILE`: 启用HTTPS的密钥文件。
6767
- `STATIC_ROOT_PATH`: 存放模板和静态文件的根目录,默认是 Gitea 的根目录。
68+
- `STATIC_CACHE_TIME`: **6h**: 静态资源文件,包括 `custom/`, `public/` 和所有上传的头像的浏览器缓存时间。
6869
- `ENABLE_GZIP`: 启用应用级别的 GZIP 压缩。
6970
- `LANDING_PAGE`: 未登录用户的默认页面,可选 `home``explore`
7071
- `LFS_START_SERVER`: 是否启用 git-lfs 支持. 可以为 `true``false`, 默认是 `false`

modules/setting/setting.go

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ var (
8787
CertFile string
8888
KeyFile string
8989
StaticRootPath string
90+
StaticCacheTime time.Duration
9091
EnableGzip bool
9192
LandingPageURL LandingPage
9293
UnixSocketPermission uint32
@@ -607,6 +608,7 @@ func NewContext() {
607608
OfflineMode = sec.Key("OFFLINE_MODE").MustBool()
608609
DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool()
609610
StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(AppWorkPath)
611+
StaticCacheTime = sec.Key("STATIC_CACHE_TIME").MustDuration(6 * time.Hour)
610612
AppDataPath = sec.Key("APP_DATA_PATH").MustString(path.Join(AppWorkPath, "data"))
611613
EnableGzip = sec.Key("ENABLE_GZIP").MustBool()
612614
EnablePprof = sec.Key("ENABLE_PPROF").MustBool(false)

routers/routes/routes.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -139,30 +139,30 @@ func NewMacaron() *macaron.Macaron {
139139
m.Use(public.Custom(
140140
&public.Options{
141141
SkipLogging: setting.DisableRouterLog,
142-
ExpiresAfter: time.Hour * 6,
142+
ExpiresAfter: setting.StaticCacheTime,
143143
},
144144
))
145145
m.Use(public.Static(
146146
&public.Options{
147147
Directory: path.Join(setting.StaticRootPath, "public"),
148148
SkipLogging: setting.DisableRouterLog,
149-
ExpiresAfter: time.Hour * 6,
149+
ExpiresAfter: setting.StaticCacheTime,
150150
},
151151
))
152152
m.Use(public.StaticHandler(
153153
setting.AvatarUploadPath,
154154
&public.Options{
155155
Prefix: "avatars",
156156
SkipLogging: setting.DisableRouterLog,
157-
ExpiresAfter: time.Hour * 6,
157+
ExpiresAfter: setting.StaticCacheTime,
158158
},
159159
))
160160
m.Use(public.StaticHandler(
161161
setting.RepositoryAvatarUploadPath,
162162
&public.Options{
163163
Prefix: "repo-avatars",
164164
SkipLogging: setting.DisableRouterLog,
165-
ExpiresAfter: time.Hour * 6,
165+
ExpiresAfter: setting.StaticCacheTime,
166166
},
167167
))
168168

0 commit comments

Comments
 (0)