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
|
|
|
|
2021-03-02 19:43:05 +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"`
|
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-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
|
|
|
|
|
}
|