Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
690e91e1
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
690e91e1
编写于
6月 02, 2020
作者:
J
jianzhiyao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
static file module:make cache file size and cache file numbers configurable
上级
50f71a8a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
10 deletion
+32
-10
admin_test.go
admin_test.go
+2
-0
config.go
config.go
+12
-0
config_test.go
config_test.go
+8
-0
staticfile.go
staticfile.go
+10
-10
未找到文件。
admin_test.go
浏览文件 @
690e91e1
...
...
@@ -52,6 +52,8 @@ func oldMap() M {
m
[
"BConfig.WebConfig.DirectoryIndex"
]
=
BConfig
.
WebConfig
.
DirectoryIndex
m
[
"BConfig.WebConfig.StaticDir"
]
=
BConfig
.
WebConfig
.
StaticDir
m
[
"BConfig.WebConfig.StaticExtensionsToGzip"
]
=
BConfig
.
WebConfig
.
StaticExtensionsToGzip
m
[
"BConfig.WebConfig.StaticCacheFileSize"
]
=
BConfig
.
WebConfig
.
StaticCacheFileSize
m
[
"BConfig.WebConfig.StaticCacheFileNum"
]
=
BConfig
.
WebConfig
.
StaticCacheFileNum
m
[
"BConfig.WebConfig.TemplateLeft"
]
=
BConfig
.
WebConfig
.
TemplateLeft
m
[
"BConfig.WebConfig.TemplateRight"
]
=
BConfig
.
WebConfig
.
TemplateRight
m
[
"BConfig.WebConfig.ViewsPath"
]
=
BConfig
.
WebConfig
.
ViewsPath
...
...
config.go
浏览文件 @
690e91e1
...
...
@@ -81,6 +81,8 @@ type WebConfig struct {
DirectoryIndex
bool
StaticDir
map
[
string
]
string
StaticExtensionsToGzip
[]
string
StaticCacheFileSize
int
StaticCacheFileNum
int
TemplateLeft
string
TemplateRight
string
ViewsPath
string
...
...
@@ -236,6 +238,8 @@ func newBConfig() *Config {
DirectoryIndex
:
false
,
StaticDir
:
map
[
string
]
string
{
"/static"
:
"static"
},
StaticExtensionsToGzip
:
[]
string
{
".css"
,
".js"
},
StaticCacheFileSize
:
1024
*
100
,
StaticCacheFileNum
:
1000
,
TemplateLeft
:
"{{"
,
TemplateRight
:
"}}"
,
ViewsPath
:
"views"
,
...
...
@@ -317,6 +321,14 @@ func assignConfig(ac config.Configer) error {
}
}
if
sfs
,
err
:=
ac
.
Int
(
"StaticCacheFileSize"
);
err
==
nil
{
BConfig
.
WebConfig
.
StaticCacheFileSize
=
sfs
}
if
sfn
,
err
:=
ac
.
Int
(
"StaticCacheFileNum"
);
err
==
nil
{
BConfig
.
WebConfig
.
StaticCacheFileNum
=
sfn
}
if
lo
:=
ac
.
String
(
"LogOutputs"
);
lo
!=
""
{
// if lo is not nil or empty
// means user has set his own LogOutputs
...
...
config_test.go
浏览文件 @
690e91e1
...
...
@@ -115,6 +115,8 @@ func TestAssignConfig_03(t *testing.T) {
ac
.
Set
(
"RunMode"
,
"online"
)
ac
.
Set
(
"StaticDir"
,
"download:down download2:down2"
)
ac
.
Set
(
"StaticExtensionsToGzip"
,
".css,.js,.html,.jpg,.png"
)
ac
.
Set
(
"StaticCacheFileSize"
,
"87456"
)
ac
.
Set
(
"StaticCacheFileNum"
,
"1254"
)
assignConfig
(
ac
)
t
.
Logf
(
"%#v"
,
BConfig
)
...
...
@@ -132,6 +134,12 @@ func TestAssignConfig_03(t *testing.T) {
if
BConfig
.
WebConfig
.
StaticDir
[
"/download2"
]
!=
"down2"
{
t
.
FailNow
()
}
if
BConfig
.
WebConfig
.
StaticCacheFileSize
!=
87456
{
t
.
FailNow
()
}
if
BConfig
.
WebConfig
.
StaticCacheFileNum
!=
1254
{
t
.
FailNow
()
}
if
len
(
BConfig
.
WebConfig
.
StaticExtensionsToGzip
)
!=
5
{
t
.
FailNow
()
}
...
...
staticfile.go
浏览文件 @
690e91e1
...
...
@@ -105,19 +105,19 @@ type serveContentReader struct {
*
bytes
.
Reader
}
const
(
//max file size to cache,default: 100k
MaxCacheFileSize
int
=
1024
*
100
//max file count to cache,default: 1000
MaxCacheFileCount
int
=
1000
)
var
(
staticFileLruCache
,
_
=
lru
.
New
(
MaxCacheFileCount
)
lruLock
sync
.
RWMutex
staticFileLruCache
*
lru
.
Cache
lruLock
sync
.
RWMutex
)
func
openFile
(
filePath
string
,
fi
os
.
FileInfo
,
acceptEncoding
string
)
(
bool
,
string
,
*
serveContentHolder
,
*
serveContentReader
,
error
)
{
if
staticFileLruCache
==
nil
{
if
BConfig
.
WebConfig
.
StaticCacheFileNum
>=
1
{
staticFileLruCache
,
_
=
lru
.
New
(
BConfig
.
WebConfig
.
StaticCacheFileNum
)
}
else
{
staticFileLruCache
,
_
=
lru
.
New
(
1
)
}
}
mapKey
:=
acceptEncoding
+
":"
+
filePath
lruLock
.
RLock
()
var
mapFile
*
serveContentHolder
...
...
@@ -158,7 +158,7 @@ func openFile(filePath string, fi os.FileInfo, acceptEncoding string) (bool, str
func
isOk
(
s
*
serveContentHolder
,
fi
os
.
FileInfo
)
bool
{
if
s
==
nil
{
return
false
}
else
if
s
.
size
>
int64
(
Max
CacheFileSize
)
{
}
else
if
s
.
size
>
int64
(
BConfig
.
WebConfig
.
Static
CacheFileSize
)
{
return
false
}
return
s
.
modTime
==
fi
.
ModTime
()
&&
s
.
originSize
==
fi
.
Size
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录