mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	缓存文件实现Sendfile
This commit is contained in:
		@@ -32,6 +32,7 @@ func (this *CreatePopupAction) RunPost(params struct {
 | 
			
		||||
	FileDir                string
 | 
			
		||||
	FileMemoryCapacityJSON []byte
 | 
			
		||||
	FileOpenFileCacheMax   int
 | 
			
		||||
	FileEnableSendfile     bool
 | 
			
		||||
 | 
			
		||||
	CapacityJSON         []byte
 | 
			
		||||
	MaxSizeJSON          []byte
 | 
			
		||||
@@ -77,7 +78,8 @@ func (this *CreatePopupAction) RunPost(params struct {
 | 
			
		||||
			MemoryPolicy: &serverconfigs.HTTPCachePolicy{
 | 
			
		||||
				Capacity: memoryCapacity,
 | 
			
		||||
			},
 | 
			
		||||
			OpenFileCache: openFileCacheConfig,
 | 
			
		||||
			OpenFileCache:  openFileCacheConfig,
 | 
			
		||||
			EnableSendfile: params.FileEnableSendfile,
 | 
			
		||||
		}
 | 
			
		||||
	case serverconfigs.CachePolicyStorageMemory:
 | 
			
		||||
		options = &serverconfigs.HTTPMemoryCacheStorage{}
 | 
			
		||||
 
 | 
			
		||||
@@ -26,13 +26,13 @@ func (this *UpdateAction) RunGet(params struct {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	configJSON := configResp.HttpCachePolicyJSON
 | 
			
		||||
	var configJSON = configResp.HttpCachePolicyJSON
 | 
			
		||||
	if len(configJSON) == 0 {
 | 
			
		||||
		this.NotFound("cachePolicy", params.CachePolicyId)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cachePolicy := &serverconfigs.HTTPCachePolicy{}
 | 
			
		||||
	var cachePolicy = &serverconfigs.HTTPCachePolicy{}
 | 
			
		||||
	err = json.Unmarshal(configJSON, cachePolicy)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
@@ -56,6 +56,7 @@ func (this *UpdateAction) RunPost(params struct {
 | 
			
		||||
	FileDir                string
 | 
			
		||||
	FileMemoryCapacityJSON []byte
 | 
			
		||||
	FileOpenFileCacheMax   int
 | 
			
		||||
	FileEnableSendfile     bool
 | 
			
		||||
 | 
			
		||||
	CapacityJSON         []byte
 | 
			
		||||
	MaxSizeJSON          []byte
 | 
			
		||||
@@ -106,7 +107,8 @@ func (this *UpdateAction) RunPost(params struct {
 | 
			
		||||
			MemoryPolicy: &serverconfigs.HTTPCachePolicy{
 | 
			
		||||
				Capacity: memoryCapacity,
 | 
			
		||||
			},
 | 
			
		||||
			OpenFileCache: openFileCacheConfig,
 | 
			
		||||
			OpenFileCache:  openFileCacheConfig,
 | 
			
		||||
			EnableSendfile: params.FileEnableSendfile,
 | 
			
		||||
		}
 | 
			
		||||
	case serverconfigs.CachePolicyStorageMemory:
 | 
			
		||||
		options = &serverconfigs.HTTPMemoryCacheStorage{}
 | 
			
		||||
 
 | 
			
		||||
@@ -4978,7 +4978,7 @@ Vue.component("http-cache-stale-config", {
 | 
			
		||||
			<td class="title">启用过时缓存</td>
 | 
			
		||||
			<td>
 | 
			
		||||
				<checkbox v-model="config.isOn"></checkbox>
 | 
			
		||||
				<p class="comment">选中后,在更新缓存失败后会尝试读取过时的缓存。</p>
 | 
			
		||||
				<p class="comment"><plus-label></plus-label>选中后,在更新缓存失败后会尝试读取过时的缓存。</p>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
		<tr v-show="config.isOn">
 | 
			
		||||
@@ -6617,7 +6617,7 @@ Vue.component("http-pages-and-shutdown-box", {
 | 
			
		||||
<input type="hidden" name="shutdownJSON" :value="JSON.stringify(shutdownConfig)"/>
 | 
			
		||||
<table class="ui table selectable definition">
 | 
			
		||||
	<tr>
 | 
			
		||||
		<td class="title">特殊页面</td>
 | 
			
		||||
		<td class="title">自定义页面</td>
 | 
			
		||||
		<td>
 | 
			
		||||
			<div v-if="pages.length > 0">
 | 
			
		||||
				<div class="ui label small basic" v-for="(page,index) in pages">
 | 
			
		||||
@@ -6628,7 +6628,7 @@ Vue.component("http-pages-and-shutdown-box", {
 | 
			
		||||
			<div>
 | 
			
		||||
				<button class="ui button small" type="button" @click.prevent="addPage()">+</button>
 | 
			
		||||
			</div>
 | 
			
		||||
			<p class="comment">根据响应状态码返回一些特殊页面,比如404,500等错误页面。</p>
 | 
			
		||||
			<p class="comment">根据响应状态码返回一些自定义页面,比如404,500等错误页面。</p>
 | 
			
		||||
		</td>
 | 
			
		||||
	</tr>	
 | 
			
		||||
	<tr>
 | 
			
		||||
@@ -7525,7 +7525,7 @@ Vue.component("http-location-labels", {
 | 
			
		||||
	<!-- 请求脚本 -->
 | 
			
		||||
	<http-location-labels-label v-if="location.web != null && location.web.requestScripts != null && ((location.web.requestScripts.initGroup != null && location.web.requestScripts.initGroup.isPrior) || (location.web.requestScripts.requestGroup != null && location.web.requestScripts.requestGroup.isPrior))" :href="url('/requestScripts')">请求脚本</http-location-labels-label>
 | 
			
		||||
	
 | 
			
		||||
	<!-- 特殊页面 -->
 | 
			
		||||
	<!-- 自定义页面 -->
 | 
			
		||||
	<div v-if="location.web != null && location.web.pages != null && location.web.pages.length > 0">
 | 
			
		||||
		<div v-for="page in location.web.pages" :key="page.id"><http-location-labels-label :href="url('/pages')">PAGE [状态码{{page.status[0]}}] -> {{page.url}}</http-location-labels-label></div>
 | 
			
		||||
	</div>
 | 
			
		||||
@@ -8628,7 +8628,7 @@ Vue.component("http-web-root-box", {
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
Vue.component("http-webp-config-box", {
 | 
			
		||||
	props: ["v-webp-config", "v-is-location", "v-is-group"],
 | 
			
		||||
	props: ["v-webp-config", "v-is-location", "v-is-group", "v-require-cache"],
 | 
			
		||||
	data: function () {
 | 
			
		||||
		let config = this.vWebpConfig
 | 
			
		||||
		if (config == null) {
 | 
			
		||||
@@ -8698,13 +8698,13 @@ Vue.component("http-webp-config-box", {
 | 
			
		||||
		<prior-checkbox :v-config="config" v-if="vIsLocation || vIsGroup"></prior-checkbox>
 | 
			
		||||
		<tbody v-show="(!vIsLocation && !vIsGroup) || config.isPrior">
 | 
			
		||||
			<tr>
 | 
			
		||||
				<td class="title">是否启用</td>
 | 
			
		||||
				<td class="title">启用</td>
 | 
			
		||||
				<td>
 | 
			
		||||
					<div class="ui checkbox">
 | 
			
		||||
						<input type="checkbox" value="1" v-model="config.isOn"/>
 | 
			
		||||
						<label></label>
 | 
			
		||||
					</div>
 | 
			
		||||
					<p class="comment">选中后表示开启自动WebP压缩。</p>
 | 
			
		||||
					<p class="comment">选中后表示开启自动WebP压缩<span v-if="vRequireCache">;只有满足缓存条件的图片内容才会被转换</span>。</p>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
		</tbody>
 | 
			
		||||
@@ -11142,6 +11142,10 @@ Vue.component("countries-selector", {
 | 
			
		||||
</div>`
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
Vue.component("raquo-item", {
 | 
			
		||||
	template: `<span class="item disabled" style="padding: 0">»</span>`
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
Vue.component("more-options-tbody", {
 | 
			
		||||
	data: function () {
 | 
			
		||||
		return {
 | 
			
		||||
@@ -11532,6 +11536,11 @@ Vue.component("optional-label", {
 | 
			
		||||
	template: `<em><span class="grey">(可选)</span></em>`
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
// Plus专属
 | 
			
		||||
Vue.component("plus-label", {
 | 
			
		||||
	template: `<span style="color: #B18701;">Plus专属功能。</span>`
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 一级菜单
 | 
			
		||||
 */
 | 
			
		||||
@@ -13904,6 +13913,39 @@ Vue.component("node-combo-box", {
 | 
			
		||||
</div>`
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
// 节点级别选择器
 | 
			
		||||
Vue.component("node-level-selector", {
 | 
			
		||||
	props: ["v-node-level"],
 | 
			
		||||
	data: function () {
 | 
			
		||||
		let levelCode = this.vNodeLevel
 | 
			
		||||
		if (levelCode == null || levelCode < 1) {
 | 
			
		||||
			levelCode = 1
 | 
			
		||||
		}
 | 
			
		||||
		return {
 | 
			
		||||
			levels: [
 | 
			
		||||
				{
 | 
			
		||||
					name: "边缘节点",
 | 
			
		||||
					code: 1,
 | 
			
		||||
					description: "普通的边缘节点。"
 | 
			
		||||
				},
 | 
			
		||||
				{
 | 
			
		||||
					name: "L2节点",
 | 
			
		||||
					code: 2,
 | 
			
		||||
					description: "特殊的边缘节点,同时负责同组上一级节点的回源。"
 | 
			
		||||
				}
 | 
			
		||||
			],
 | 
			
		||||
			levelCode: levelCode
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	template: `<div>
 | 
			
		||||
	<select class="ui dropdown auto-width" name="level" v-model="levelCode">
 | 
			
		||||
	<option v-for="level in levels" :value="level.code">{{level.name}}</option>
 | 
			
		||||
</select>
 | 
			
		||||
<p class="comment" v-if="typeof(levels[levelCode - 1]) != null"><plus-label
 | 
			
		||||
></plus-label>{{levels[levelCode - 1].description}}</p>
 | 
			
		||||
</div>`
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
Vue.component("dns-route-selector", {
 | 
			
		||||
	props: ["v-all-routes", "v-routes"],
 | 
			
		||||
	data: function () {
 | 
			
		||||
 
 | 
			
		||||
@@ -48,3 +48,8 @@ Vue.component("grey-label", {
 | 
			
		||||
Vue.component("optional-label", {
 | 
			
		||||
	template: `<em><span class="grey">(可选)</span></em>`
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
// Plus专属
 | 
			
		||||
Vue.component("plus-label", {
 | 
			
		||||
	template: `<span style="color: #B18701;">Plus专属功能。</span>`
 | 
			
		||||
})
 | 
			
		||||
@@ -26,6 +26,7 @@ Vue.component("node-level-selector", {
 | 
			
		||||
	<select class="ui dropdown auto-width" name="level" v-model="levelCode">
 | 
			
		||||
	<option v-for="level in levels" :value="level.code">{{level.name}}</option>
 | 
			
		||||
</select>
 | 
			
		||||
<p class="comment" v-if="typeof(levels[levelCode - 1]) != null">{{levels[levelCode - 1].description}}</p>
 | 
			
		||||
<p class="comment" v-if="typeof(levels[levelCode - 1]) != null"><plus-label
 | 
			
		||||
></plus-label>{{levels[levelCode - 1].description}}</p>
 | 
			
		||||
</div>`
 | 
			
		||||
})
 | 
			
		||||
@@ -33,7 +33,7 @@ Vue.component("http-cache-stale-config", {
 | 
			
		||||
			<td class="title">启用过时缓存</td>
 | 
			
		||||
			<td>
 | 
			
		||||
				<checkbox v-model="config.isOn"></checkbox>
 | 
			
		||||
				<p class="comment">选中后,在更新缓存失败后会尝试读取过时的缓存。</p>
 | 
			
		||||
				<p class="comment"><plus-label></plus-label>选中后,在更新缓存失败后会尝试读取过时的缓存。</p>
 | 
			
		||||
			</td>
 | 
			
		||||
		</tr>
 | 
			
		||||
		<tr v-show="config.isOn">
 | 
			
		||||
 
 | 
			
		||||
@@ -45,6 +45,13 @@
 | 
			
		||||
                    <input type="text" name="fileOpenFileCacheMax" maxlength="6" value="0" style="width: 10em"/>
 | 
			
		||||
                    <p class="comment">保持缓存文件句柄,提升缓存文件打开速度,建议数量是缓存文件数量的10%。</p>
 | 
			
		||||
                </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td class="color-border" v-show="teaIsPlus">开启Sendfile</td>
 | 
			
		||||
                <td>
 | 
			
		||||
                    <checkbox name="fileEnableSendfile"></checkbox>
 | 
			
		||||
                    <p class="comment"><plus-label></plus-label>使用sendfile提升发送缓存文件的效率。</p>
 | 
			
		||||
                </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
		</tbody>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -54,6 +54,13 @@
 | 
			
		||||
                        <input type="text" name="fileOpenFileCacheMax" v-model="fileOpenFileCacheMax" maxlength="6" value="0" style="width: 10em"/>
 | 
			
		||||
                        <p class="comment">保持缓存文件句柄,提升缓存文件打开速度,建议数量是缓存文件数量的10%。</p>
 | 
			
		||||
                    </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
                <tr>
 | 
			
		||||
                    <td class="color-border" v-show="teaIsPlus">开启Sendfile</td>
 | 
			
		||||
                    <td>
 | 
			
		||||
                        <checkbox name="fileEnableSendfile" v-model="cachePolicy.options.enableSendfile"></checkbox>
 | 
			
		||||
                        <p class="comment"><plus-label></plus-label>使用sendfile提升发送缓存文件的效率。</p>
 | 
			
		||||
                    </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
			</tbody>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user