1.4.5.2
This commit is contained in:
84
EdgeNode/internal/utils/ttlcache/option.go
Normal file
84
EdgeNode/internal/utils/ttlcache/option.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package ttlcache
|
||||
|
||||
import "time"
|
||||
|
||||
type OptionInterface interface {
|
||||
}
|
||||
|
||||
type PiecesOption struct {
|
||||
Count int
|
||||
}
|
||||
|
||||
func NewPiecesOption(count int) *PiecesOption {
|
||||
return &PiecesOption{Count: count}
|
||||
}
|
||||
|
||||
type MaxItemsOption struct {
|
||||
Count int
|
||||
}
|
||||
|
||||
func NewMaxItemsOption(count int) *MaxItemsOption {
|
||||
return &MaxItemsOption{Count: count}
|
||||
}
|
||||
|
||||
// MinPiecesOption 最小分片数选项
|
||||
type MinPiecesOption struct {
|
||||
Count int
|
||||
}
|
||||
|
||||
func NewMinPiecesOption(count int) *MinPiecesOption {
|
||||
return &MinPiecesOption{Count: count}
|
||||
}
|
||||
|
||||
// MaxPiecesOption 最大分片数选项
|
||||
type MaxPiecesOption struct {
|
||||
Count int
|
||||
}
|
||||
|
||||
func NewMaxPiecesOption(count int) *MaxPiecesOption {
|
||||
return &MaxPiecesOption{Count: count}
|
||||
}
|
||||
|
||||
// GCConfigOption GC 配置选项
|
||||
type GCConfigOption struct {
|
||||
BaseInterval time.Duration
|
||||
MinInterval time.Duration
|
||||
MaxInterval time.Duration
|
||||
Adaptive bool
|
||||
SampleSize int
|
||||
}
|
||||
|
||||
func NewGCConfigOption() *GCConfigOption {
|
||||
return &GCConfigOption{
|
||||
BaseInterval: 2 * time.Second,
|
||||
MinInterval: 1 * time.Second,
|
||||
MaxInterval: 10 * time.Second,
|
||||
Adaptive: true,
|
||||
SampleSize: 100,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *GCConfigOption) WithBaseInterval(interval time.Duration) *GCConfigOption {
|
||||
this.BaseInterval = interval
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *GCConfigOption) WithMinInterval(interval time.Duration) *GCConfigOption {
|
||||
this.MinInterval = interval
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *GCConfigOption) WithMaxInterval(interval time.Duration) *GCConfigOption {
|
||||
this.MaxInterval = interval
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *GCConfigOption) WithAdaptive(adaptive bool) *GCConfigOption {
|
||||
this.Adaptive = adaptive
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *GCConfigOption) WithSampleSize(size int) *GCConfigOption {
|
||||
this.SampleSize = size
|
||||
return this
|
||||
}
|
||||
Reference in New Issue
Block a user