Files
EdgeNode/internal/caches/item.go

32 lines
634 B
Go
Raw Normal View History

2020-10-04 14:30:42 +08:00
package caches
import "time"
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"`
2020-10-04 14:30:42 +08:00
}
func (this *Item) IsExpired() bool {
return this.ExpiredAt < time.Now().Unix()
}
2021-01-13 12:02:50 +08:00
func (this *Item) TotalSize() int64 {
2021-05-24 09:37:37 +08:00
return this.Size() + this.MetaSize + int64(len(this.Key)) + 64
2021-01-13 12:02:50 +08:00
}
func (this *Item) Size() int64 {
return this.HeaderSize + this.BodySize
}