Files
EdgeNode/internal/caches/item.go

36 lines
804 B
Go
Raw Normal View History

2020-10-04 14:30:42 +08:00
package caches
2021-06-11 14:53:51 +08:00
import (
"github.com/TeaOSLab/EdgeNode/internal/utils"
)
2020-10-04 14:30:42 +08:00
type ItemType = int
const (
ItemTypeFile ItemType = 1
ItemTypeMemory ItemType = 2
)
2020-10-04 14:30:42 +08:00
type Item struct {
2021-05-19 12:07:35 +08:00
Type ItemType `json:"type"`
Key string `json:"key"`
ExpiredAt int64 `json:"expiredAt"`
HeaderSize int64 `json:"headerSize"`
BodySize int64 `json:"bodySize"`
MetaSize int64 `json:"metaSize"`
2021-06-13 17:37:57 +08:00
Host string `json:"host"` // 主机名
ServerId int64 `json:"serverId"` // 服务ID
2020-10-04 14:30:42 +08:00
}
func (this *Item) IsExpired() bool {
2021-06-11 14:53:51 +08:00
return this.ExpiredAt < utils.UnixTime()
2020-10-04 14:30:42 +08:00
}
2021-01-13 12:02:50 +08:00
func (this *Item) TotalSize() int64 {
2021-10-17 20:23:10 +08:00
return this.Size() + this.MetaSize + int64(len(this.Key)) + int64(len(this.Host)) + 64
2021-01-13 12:02:50 +08:00
}
func (this *Item) Size() int64 {
return this.HeaderSize + this.BodySize
}