Files
EdgeNode/internal/caches/item.go
2021-05-19 12:07:35 +08:00

32 lines
629 B
Go

package caches
import "time"
type ItemType = int
const (
ItemTypeFile ItemType = 1
ItemTypeMemory ItemType = 2
)
type Item struct {
Type ItemType `json:"type"`
Key string `json:"key"`
ExpiredAt int64 `json:"expiredAt"`
HeaderSize int64 `json:"headerSize"`
BodySize int64 `json:"bodySize"`
MetaSize int64 `json:"metaSize"`
}
func (this *Item) IsExpired() bool {
return this.ExpiredAt < time.Now().Unix()
}
func (this *Item) TotalSize() int64 {
return this.Size() + this.MetaSize + int64(len(this.Key))
}
func (this *Item) Size() int64 {
return this.HeaderSize + this.BodySize
}