mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 21:50:28 +08:00 
			
		
		
		
	文件缓存策略支持二级缓存(内存 | 文件)
This commit is contained in:
		@@ -6,6 +6,7 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
)
 | 
			
		||||
@@ -29,6 +30,7 @@ func (this *CreatePopupAction) RunPost(params struct {
 | 
			
		||||
 | 
			
		||||
	// file
 | 
			
		||||
	FileDir                string
 | 
			
		||||
	FileMemoryCapacityJSON []byte
 | 
			
		||||
 | 
			
		||||
	CapacityJSON []byte
 | 
			
		||||
	MaxSizeJSON  []byte
 | 
			
		||||
@@ -50,8 +52,21 @@ func (this *CreatePopupAction) RunPost(params struct {
 | 
			
		||||
		params.Must.
 | 
			
		||||
			Field("fileDir", params.FileDir).
 | 
			
		||||
			Require("请输入缓存目录")
 | 
			
		||||
 | 
			
		||||
		memoryCapacity := &shared.SizeCapacity{}
 | 
			
		||||
		if len(params.FileMemoryCapacityJSON) > 0 {
 | 
			
		||||
			err := json.Unmarshal(params.FileMemoryCapacityJSON, memoryCapacity)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		options = &serverconfigs.HTTPFileCacheStorage{
 | 
			
		||||
			Dir: params.FileDir,
 | 
			
		||||
			MemoryPolicy: &serverconfigs.HTTPCachePolicy{
 | 
			
		||||
				Capacity: memoryCapacity,
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
	case serverconfigs.CachePolicyStorageMemory:
 | 
			
		||||
		options = &serverconfigs.HTTPMemoryCacheStorage{
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -53,6 +54,7 @@ func (this *UpdateAction) RunPost(params struct {
 | 
			
		||||
 | 
			
		||||
	// file
 | 
			
		||||
	FileDir                string
 | 
			
		||||
	FileMemoryCapacityJSON []byte
 | 
			
		||||
 | 
			
		||||
	CapacityJSON []byte
 | 
			
		||||
	MaxSizeJSON  []byte
 | 
			
		||||
@@ -74,8 +76,21 @@ func (this *UpdateAction) RunPost(params struct {
 | 
			
		||||
		params.Must.
 | 
			
		||||
			Field("fileDir", params.FileDir).
 | 
			
		||||
			Require("请输入缓存目录")
 | 
			
		||||
 | 
			
		||||
		memoryCapacity := &shared.SizeCapacity{}
 | 
			
		||||
		if len(params.FileMemoryCapacityJSON) > 0 {
 | 
			
		||||
			err := json.Unmarshal(params.FileMemoryCapacityJSON, memoryCapacity)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				this.ErrorPage(err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		options = &serverconfigs.HTTPFileCacheStorage{
 | 
			
		||||
			Dir: params.FileDir,
 | 
			
		||||
			MemoryPolicy: &serverconfigs.HTTPCachePolicy{
 | 
			
		||||
				Capacity: memoryCapacity,
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
	case serverconfigs.CachePolicyStorageMemory:
 | 
			
		||||
		options = &serverconfigs.HTTPMemoryCacheStorage{
 | 
			
		||||
 
 | 
			
		||||
@@ -25,16 +25,32 @@
 | 
			
		||||
					<p class="comment">存放文件缓存的目录,通常填写绝对路径。</p>
 | 
			
		||||
				</td>
 | 
			
		||||
			</tr>
 | 
			
		||||
		</tbody>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            <tr>
 | 
			
		||||
			<td>缓存最大容量</td>
 | 
			
		||||
                <td class="color-border">文件目录最大容量</td>
 | 
			
		||||
                <td>
 | 
			
		||||
                    <size-capacity-box :v-name="'capacityJSON'" :v-count="0" :v-unit="'gb'"></size-capacity-box>
 | 
			
		||||
				<p class="comment">允许缓存的最大内容长度,如果为0表示没有限制。</p>
 | 
			
		||||
                    <p class="comment">作为二级缓存的文件目录允许缓存的最大容量,如果为0表示没有限制。</p>
 | 
			
		||||
                </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td class="color-border">内存最大容量</td>
 | 
			
		||||
                <td>
 | 
			
		||||
                    <size-capacity-box :v-name="'fileMemoryCapacityJSON'" :v-count="1" :v-unit="'gb'"></size-capacity-box>
 | 
			
		||||
                    <p class="comment">作为一级缓存的内存最大容量,如果为0表示不使用内存作为一级缓存。</p>
 | 
			
		||||
                </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
		</tbody>
 | 
			
		||||
 | 
			
		||||
        <tbody v-if="policyType != 'file'">
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td>内存最大容量</td>
 | 
			
		||||
                <td>
 | 
			
		||||
                    <size-capacity-box :v-name="'capacityJSON'" :v-count="0" :v-unit="'gb'"></size-capacity-box>
 | 
			
		||||
                    <p class="comment">允许缓存的最大容量,如果为0表示没有限制。</p>
 | 
			
		||||
                </td>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </tbody>
 | 
			
		||||
 | 
			
		||||
		<tr>
 | 
			
		||||
			<td colspan="2"><more-options-indicator></more-options-indicator></td>
 | 
			
		||||
		</tr>
 | 
			
		||||
 
 | 
			
		||||
@@ -26,16 +26,31 @@
 | 
			
		||||
                <p class="comment">存放文件缓存的目录,通常填写绝对路径。</p>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td class="color-border">文件目录最大容量</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <size-capacity-view :v-value="cachePolicy.capacity" :v-default-text="'不限'"></size-capacity-view>
 | 
			
		||||
                <p class="comment">作为二级缓存的文件目录允许缓存的最大容量,如果为0表示没有限制。</p>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr v-if="cachePolicy.options.memoryPolicy != null && cachePolicy.options.memoryPolicy.capacity != null && cachePolicy.options.memoryPolicy.capacity.count > 0">
 | 
			
		||||
            <td class="color-border">内存最大容量</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                <size-capacity-view :v-value="cachePolicy.options.memoryPolicy.capacity"></size-capacity-view>
 | 
			
		||||
                <p class="comment">作为一级缓存的内存最大容量,如果为0表示不使用内存作为一级缓存。</p>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
    </tbody>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
   <tbody v-if="cachePolicy.type != 'file'">
 | 
			
		||||
       <tr>
 | 
			
		||||
           <td>缓存最大容量</td>
 | 
			
		||||
           <td>
 | 
			
		||||
               <size-capacity-view :v-value="cachePolicy.capacity" :v-default-text="'不限'"></size-capacity-view>
 | 
			
		||||
            <p class="comment">允许缓存的最大内容长度,如果为0表示没有限制。</p>
 | 
			
		||||
               <p class="comment">允许缓存的最大容量,如果为0表示没有限制。</p>
 | 
			
		||||
           </td>
 | 
			
		||||
       </tr>
 | 
			
		||||
   </tbody>
 | 
			
		||||
    <tr>
 | 
			
		||||
        <td colspan="2"><more-options-indicator></more-options-indicator></td>
 | 
			
		||||
    </tr>
 | 
			
		||||
 
 | 
			
		||||
@@ -27,16 +27,38 @@
 | 
			
		||||
						<p class="comment">存放文件缓存的目录,通常填写绝对路径。</p>
 | 
			
		||||
					</td>
 | 
			
		||||
				</tr>
 | 
			
		||||
                <tr>
 | 
			
		||||
                    <td class="color-border">文件目录最大容量</td>
 | 
			
		||||
                    <td>
 | 
			
		||||
                        <size-capacity-box :v-name="'capacityJSON'" :v-value="cachePolicy.capacity" :v-count="0" :v-unit="'gb'"></size-capacity-box>
 | 
			
		||||
                        <p class="comment">作为二级缓存的文件目录允许缓存的最大容量,如果为0表示没有限制。</p>
 | 
			
		||||
                    </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
                <tr v-if="cachePolicy.options.memoryPolicy != null && cachePolicy.options.memoryPolicy.capacity != null">
 | 
			
		||||
                    <td class="color-border">内存最大容量</td>
 | 
			
		||||
                    <td>
 | 
			
		||||
                        <size-capacity-box :v-name="'fileMemoryCapacityJSON'" :v-value="cachePolicy.options.memoryPolicy.capacity" :v-count="1" :v-unit="'gb'"></size-capacity-box>
 | 
			
		||||
                        <p class="comment">作为一级缓存的内存最大容量,如果为0表示不使用内存作为一级缓存。</p>
 | 
			
		||||
                    </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
                <tr v-if="cachePolicy.options.memoryPolicy == null || cachePolicy.options.memoryPolicy.capacity == null">
 | 
			
		||||
                    <td class="color-border">内存最大容量</td>
 | 
			
		||||
                    <td>
 | 
			
		||||
                        <size-capacity-box :v-name="'fileMemoryCapacityJSON'" :v-count="0" :v-unit="'gb'"></size-capacity-box>
 | 
			
		||||
                        <p class="comment">作为一级缓存的内存最大容量,如果为0表示不使用内存作为一级缓存。</p>
 | 
			
		||||
                    </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
			</tbody>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            <tbody v-if="policyType != 'file'">
 | 
			
		||||
                <tr>
 | 
			
		||||
                    <td>缓存最大容量</td>
 | 
			
		||||
                    <td>
 | 
			
		||||
                        <size-capacity-box :v-name="'capacityJSON'" :v-value="cachePolicy.capacity" :v-count="0" :v-unit="'gb'"></size-capacity-box>
 | 
			
		||||
					<p class="comment">允许缓存的最大内容长度,如果为0表示没有限制。</p>
 | 
			
		||||
                        <p class="comment">允许缓存的最大容量,如果为0表示没有限制。</p>
 | 
			
		||||
                    </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
            </tbody>
 | 
			
		||||
			<tr>
 | 
			
		||||
				<td colspan="2"><more-options-indicator></more-options-indicator></td>
 | 
			
		||||
			</tr>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user