节点状态中增加缓存用量数据

This commit is contained in:
刘祥超
2021-05-13 11:50:36 +08:00
parent d9d06b7be9
commit 8caa03175c
5 changed files with 67 additions and 11 deletions
+24
View File
@@ -138,3 +138,27 @@ func (this *Manager) NewStorageWithPolicy(policy *serverconfigs.HTTPCachePolicy)
}
return nil
}
// TotalDiskSize 消耗的磁盘尺寸
func (this *Manager) TotalDiskSize() int64 {
this.locker.RLock()
defer this.locker.RUnlock()
total := int64(0)
for _, storage := range this.storageMap {
total += storage.TotalDiskSize()
}
return total
}
// TotalMemorySize 消耗的内存尺寸
func (this *Manager) TotalMemorySize() int64 {
this.locker.RLock()
defer this.locker.RUnlock()
total := int64(0)
for _, storage := range this.storageMap {
total += storage.TotalMemorySize()
}
return total
}
+13
View File
@@ -496,6 +496,19 @@ func (this *FileStorage) Stop() {
}
}
// TotalDiskSize 消耗的磁盘尺寸
func (this *FileStorage) TotalDiskSize() int64 {
return atomic.LoadInt64(&this.totalSize)
}
// TotalMemorySize 内存尺寸
func (this *FileStorage) TotalMemorySize() int64 {
if this.memoryStorage == nil {
return 0
}
return this.memoryStorage.TotalMemorySize()
}
// 绝对路径
func (this *FileStorage) dir() string {
return this.cacheConfig.Dir + "/p" + strconv.FormatInt(this.policy.Id, 10) + "/"
+17 -11
View File
@@ -4,35 +4,41 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
)
// 缓存存储接口
// StorageInterface 缓存存储接口
type StorageInterface interface {
// 初始化
// Init 初始化
Init() error
// 读取缓存
// OpenReader 读取缓存
OpenReader(key string) (Reader, error)
// 打开缓存写入器等待写入
// OpenWriter 打开缓存写入器等待写入
OpenWriter(key string, expiredAt int64, status int) (Writer, error)
// 删除某个键值对应的缓存
// Delete 删除某个键值对应的缓存
Delete(key string) error
// 统计缓存
// Stat 统计缓存
Stat() (*Stat, error)
// 清除所有缓存
// TotalDiskSize 消耗的磁盘尺寸
TotalDiskSize() int64
// TotalMemorySize 内存尺寸
TotalMemorySize() int64
// CleanAll 清除所有缓存
CleanAll() error
// 批量删除缓存
// Purge 批量删除缓存
Purge(keys []string, urlType string) error
// 停止缓存策略
// Stop 停止缓存策略
Stop()
// 获取当前存储的Policy
// Policy 获取当前存储的Policy
Policy() *serverconfigs.HTTPCachePolicy
// 将缓存添加到列表
// AddToList 将缓存添加到列表
AddToList(item *Item)
}
+10
View File
@@ -183,6 +183,16 @@ func (this *MemoryStorage) AddToList(item *Item) {
this.list.Add(hash, item)
}
// TotalDiskSize 消耗的磁盘尺寸
func (this *MemoryStorage) TotalDiskSize() int64 {
return 0
}
// TotalMemorySize 内存尺寸
func (this *MemoryStorage) TotalMemorySize() int64 {
return atomic.LoadInt64(&this.totalSize)
}
// 计算Key Hash
func (this *MemoryStorage) hash(key string) uint64 {
return xxhash.Sum64String(key)