From 5b7eaf08ae8e68b3981d59ec9051b44f603b51df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 12 Jan 2022 21:09:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0open=20file=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/servers/components/cache/createPopup.go | 13 +++++++++++-- .../default/servers/components/cache/update.go | 13 +++++++++++-- .../servers/components/cache/createPopup.html | 9 ++++++++- .../@default/servers/components/cache/policy.html | 4 ++++ .../@default/servers/components/cache/update.html | 7 +++++++ .../@default/servers/components/cache/update.js | 5 +++++ 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/internal/web/actions/default/servers/components/cache/createPopup.go b/internal/web/actions/default/servers/components/cache/createPopup.go index d451be55..07c8f23a 100644 --- a/internal/web/actions/default/servers/components/cache/createPopup.go +++ b/internal/web/actions/default/servers/components/cache/createPopup.go @@ -31,6 +31,7 @@ func (this *CreatePopupAction) RunPost(params struct { // file FileDir string FileMemoryCapacityJSON []byte + FileOpenFileCacheMax int CapacityJSON []byte MaxSizeJSON []byte @@ -62,15 +63,23 @@ func (this *CreatePopupAction) RunPost(params struct { } } + var openFileCacheConfig *serverconfigs.OpenFileCacheConfig + if params.FileOpenFileCacheMax > 0 { + openFileCacheConfig = &serverconfigs.OpenFileCacheConfig{ + IsOn: true, + Max: params.FileOpenFileCacheMax, + } + } + options = &serverconfigs.HTTPFileCacheStorage{ Dir: params.FileDir, MemoryPolicy: &serverconfigs.HTTPCachePolicy{ Capacity: memoryCapacity, }, + OpenFileCache: openFileCacheConfig, } case serverconfigs.CachePolicyStorageMemory: - options = &serverconfigs.HTTPMemoryCacheStorage{ - } + options = &serverconfigs.HTTPMemoryCacheStorage{} default: this.Fail("请选择正确的缓存类型") } diff --git a/internal/web/actions/default/servers/components/cache/update.go b/internal/web/actions/default/servers/components/cache/update.go index 0de9d202..540a6ebd 100644 --- a/internal/web/actions/default/servers/components/cache/update.go +++ b/internal/web/actions/default/servers/components/cache/update.go @@ -55,6 +55,7 @@ func (this *UpdateAction) RunPost(params struct { // file FileDir string FileMemoryCapacityJSON []byte + FileOpenFileCacheMax int CapacityJSON []byte MaxSizeJSON []byte @@ -91,15 +92,23 @@ func (this *UpdateAction) RunPost(params struct { } } + var openFileCacheConfig *serverconfigs.OpenFileCacheConfig + if params.FileOpenFileCacheMax > 0 { + openFileCacheConfig = &serverconfigs.OpenFileCacheConfig{ + IsOn: true, + Max: params.FileOpenFileCacheMax, + } + } + options = &serverconfigs.HTTPFileCacheStorage{ Dir: params.FileDir, MemoryPolicy: &serverconfigs.HTTPCachePolicy{ Capacity: memoryCapacity, }, + OpenFileCache: openFileCacheConfig, } case serverconfigs.CachePolicyStorageMemory: - options = &serverconfigs.HTTPMemoryCacheStorage{ - } + options = &serverconfigs.HTTPMemoryCacheStorage{} default: this.Fail("请选择正确的缓存类型") } diff --git a/web/views/@default/servers/components/cache/createPopup.html b/web/views/@default/servers/components/cache/createPopup.html index b5437478..5c930fb3 100644 --- a/web/views/@default/servers/components/cache/createPopup.html +++ b/web/views/@default/servers/components/cache/createPopup.html @@ -26,7 +26,7 @@ - 文件目录最大容量 + 文件目录最大容量 *

作为二级缓存的文件目录允许缓存的最大容量,如果为0表示没有限制。

@@ -38,6 +38,13 @@

作为一级缓存的内存最大容量,如果为0表示不使用内存作为一级缓存。

+ + + 缓存文件句柄缓存 + + +

保持缓存文件句柄,提升缓存文件打开速度,建议数量是缓存文件数量的10%。

+ diff --git a/web/views/@default/servers/components/cache/policy.html b/web/views/@default/servers/components/cache/policy.html index 4720942d..598db48f 100644 --- a/web/views/@default/servers/components/cache/policy.html +++ b/web/views/@default/servers/components/cache/policy.html @@ -40,6 +40,10 @@

作为一级缓存的内存最大容量,如果为0表示不使用内存作为一级缓存。

+ + 缓存文件句柄缓存 + {{cachePolicy.options.openFileCache.max}} + diff --git a/web/views/@default/servers/components/cache/update.html b/web/views/@default/servers/components/cache/update.html index 45346c43..46da2c07 100644 --- a/web/views/@default/servers/components/cache/update.html +++ b/web/views/@default/servers/components/cache/update.html @@ -47,6 +47,13 @@

作为一级缓存的内存最大容量,如果为0表示不使用内存作为一级缓存。

+ + + 缓存文件句柄缓存 + + +

保持缓存文件句柄,提升缓存文件打开速度,建议数量是缓存文件数量的10%。

+ diff --git a/web/views/@default/servers/components/cache/update.js b/web/views/@default/servers/components/cache/update.js index 6d5dc6a5..c4b6494f 100644 --- a/web/views/@default/servers/components/cache/update.js +++ b/web/views/@default/servers/components/cache/update.js @@ -2,4 +2,9 @@ Tea.context(function () { this.success = NotifyReloadSuccess("保存成功 ") this.policyType = this.cachePolicy.type + + this.fileOpenFileCacheMax = 0 + if (this.cachePolicy.type == "file" && this.cachePolicy.options.openFileCache != null && this.cachePolicy.options.openFileCache.isOn && this.cachePolicy.options.openFileCache.max > 0) { + this.fileOpenFileCacheMax = this.cachePolicy.options.openFileCache.max + } }) \ No newline at end of file