85 lines
1.7 KiB
Go
85 lines
1.7 KiB
Go
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
|
|
}
|