缓存策略增加“允许读取不完整的Partial Content”选项

This commit is contained in:
GoEdgeLab
2024-05-07 20:04:39 +08:00
parent f3ae59dcbe
commit 60fb184d15
7 changed files with 51 additions and 18 deletions

View File

@@ -29,11 +29,12 @@ func FindCachePolicy(parent *actionutils.ParentAction, cachePolicyId int64) (*se
if len(resp.HttpCachePolicyJSON) == 0 { if len(resp.HttpCachePolicyJSON) == 0 {
return nil, errors.New("cache policy not found") return nil, errors.New("cache policy not found")
} }
config := &serverconfigs.HTTPCachePolicy{} var config = &serverconfigs.HTTPCachePolicy{}
err = json.Unmarshal(resp.HttpCachePolicyJSON, config) err = json.Unmarshal(resp.HttpCachePolicyJSON, config)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return config, nil return config, nil
} }

View File

@@ -37,11 +37,12 @@ func (this *CreatePopupAction) RunPost(params struct {
FileEnableSendfile bool FileEnableSendfile bool
FileMinFreeSizeJSON []byte FileMinFreeSizeJSON []byte
CapacityJSON []byte CapacityJSON []byte
MaxSizeJSON []byte MaxSizeJSON []byte
FetchTimeoutJSON []byte FetchTimeoutJSON []byte
SyncCompressionCache bool SyncCompressionCache bool
EnableMMAP bool EnableMMAP bool
EnableIncompletePartialContent bool
Description string Description string
IsOn bool IsOn bool
@@ -95,10 +96,11 @@ func (this *CreatePopupAction) RunPost(params struct {
MemoryPolicy: &serverconfigs.HTTPCachePolicy{ MemoryPolicy: &serverconfigs.HTTPCachePolicy{
Capacity: memoryCapacity, Capacity: memoryCapacity,
}, },
OpenFileCache: openFileCacheConfig, OpenFileCache: openFileCacheConfig,
EnableSendfile: params.FileEnableSendfile, EnableSendfile: params.FileEnableSendfile,
MinFreeSize: minFreeSize, MinFreeSize: minFreeSize,
EnableMMAP: params.EnableMMAP, EnableMMAP: params.EnableMMAP,
EnableIncompletePartialContent: params.EnableIncompletePartialContent,
} }
case serverconfigs.CachePolicyStorageMemory: case serverconfigs.CachePolicyStorageMemory:
options = &serverconfigs.HTTPMemoryCacheStorage{} options = &serverconfigs.HTTPMemoryCacheStorage{}

View File

@@ -59,6 +59,14 @@ func (this *UpdateAction) RunGet(params struct {
cachePolicy.Options["enableMMAP"] = false cachePolicy.Options["enableMMAP"] = false
} }
} }
// fix enableIncompletePartialContent
{
_, ok := cachePolicy.Options["enableIncompletePartialContent"]
if !ok {
cachePolicy.Options["enableIncompletePartialContent"] = true
}
}
} }
this.Data["cachePolicy"] = cachePolicy this.Data["cachePolicy"] = cachePolicy
@@ -87,7 +95,8 @@ func (this *UpdateAction) RunPost(params struct {
SyncCompressionCache bool SyncCompressionCache bool
FetchTimeoutJSON []byte FetchTimeoutJSON []byte
EnableMMAP bool EnableMMAP bool
EnableIncompletePartialContent bool
Description string Description string
IsOn bool IsOn bool
@@ -146,10 +155,11 @@ func (this *UpdateAction) RunPost(params struct {
MemoryPolicy: &serverconfigs.HTTPCachePolicy{ MemoryPolicy: &serverconfigs.HTTPCachePolicy{
Capacity: memoryCapacity, Capacity: memoryCapacity,
}, },
OpenFileCache: openFileCacheConfig, OpenFileCache: openFileCacheConfig,
EnableSendfile: params.FileEnableSendfile, EnableSendfile: params.FileEnableSendfile,
MinFreeSize: minFreeSize, MinFreeSize: minFreeSize,
EnableMMAP: params.EnableMMAP, EnableMMAP: params.EnableMMAP,
EnableIncompletePartialContent: params.EnableIncompletePartialContent,
} }
case serverconfigs.CachePolicyStorageMemory: case serverconfigs.CachePolicyStorageMemory:
options = &serverconfigs.HTTPMemoryCacheStorage{} options = &serverconfigs.HTTPMemoryCacheStorage{}

View File

@@ -84,6 +84,13 @@
<p class="comment"><pro-warning-label></pro-warning-label><plus-label></plus-label>使用sendfile提升发送缓存文件的效率。</p> <p class="comment"><pro-warning-label></pro-warning-label><plus-label></plus-label>使用sendfile提升发送缓存文件的效率。</p>
</td> </td>
</tr> </tr>
<tr>
<td class="color-border">允许读取不完整的Partial Content</td>
<td>
<checkbox name="enableIncompletePartialContent" checked="checked"></checkbox>
<p class="comment">允许在有一部分内容缓存的情况下读取分区内容,剩余的部分将会自动回源读取。</p>
</td>
</tr>
<tr v-show="moreOptionsVisible && policyType == 'file'"> <tr v-show="moreOptionsVisible && policyType == 'file'">
<td class="color-border">启用MMAP</td> <td class="color-border">启用MMAP</td>
<td> <td>

View File

@@ -58,11 +58,16 @@
<td class="color-border">缓存硬盘最小空余空间</td> <td class="color-border">缓存硬盘最小空余空间</td>
<td><size-capacity-view :v-value="cachePolicy.options.minFreeSize"></size-capacity-view></td> <td><size-capacity-view :v-value="cachePolicy.options.minFreeSize"></size-capacity-view></td>
</tr> </tr>
<tr v-if="cachePolicy.options != null"> <tr v-if="cachePolicy.options.enableIncompletePartialContent">
<td class="color-border">允许读取不完整的Partial Content</td>
<td>
<span class="green">Y</span>
</td>
</tr>
<tr v-if="cachePolicy.options.enableMMAP">
<td class="color-border">启用MMAP</td> <td class="color-border">启用MMAP</td>
<td> <td>
<span class="green" v-if="cachePolicy.options.enableMMAP || cachePolicy.options.enableMMAP == null">Y</span> <span>Y</span>
<span class="disabled" v-else>N</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@@ -91,6 +91,13 @@
<p class="comment"><pro-warning-label></pro-warning-label><plus-label></plus-label>使用sendfile提升发送缓存文件的效率。</p> <p class="comment"><pro-warning-label></pro-warning-label><plus-label></plus-label>使用sendfile提升发送缓存文件的效率。</p>
</td> </td>
</tr> </tr>
<tr>
<td class="color-border">允许读取不完整的Partial Content</td>
<td>
<checkbox name="enableIncompletePartialContent" v-model="cachePolicy.options.enableIncompletePartialContent"></checkbox>
<p class="comment">允许在有一部分内容缓存的情况下读取分区内容,剩余的部分将会自动回源读取。</p>
</td>
</tr>
<tr> <tr>
<td class="color-border">启用MMAP</td> <td class="color-border">启用MMAP</td>
<td> <td>

View File

@@ -13,6 +13,7 @@ Tea.context(function () {
let options = this.cachePolicy.options let options = this.cachePolicy.options
if (options != null && typeof options == "object" && typeof options["dir"] === "undefined") { if (options != null && typeof options == "object" && typeof options["dir"] === "undefined") {
options["enableMMAP"] = false options["enableMMAP"] = false
options["enableIncompletePartialContent"] = true
options["dir"] = "/opt/cache" options["dir"] = "/opt/cache"
options["memoryPolicy"] = { options["memoryPolicy"] = {
capacity: { capacity: {