-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
54 lines (47 loc) · 1.1 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package ttlcache
// options provides all optional parameters
type options struct {
bucketsCount int
bucketsMapPreAllocSize int
cleanInterval int // seconds
}
// Option function
type Option func(*options)
func setOptions(optL ...Option) *options {
opts := &options{
bucketsCount: 128,
bucketsMapPreAllocSize: 128,
cleanInterval: 10, // seconds
}
for _, opt := range optL {
opt(opts)
}
return opts
}
// BucketsCount can effectively reduce the number of competing occurrences in concurrent access to ttlcache.
func BucketsCount(v int) Option {
if v < 1 {
panic("BucketsCount: param is illegal")
}
return func(o *options) {
o.bucketsCount = v
}
}
// BucketsMapPreAllocSize map prealloc size
func BucketsMapPreAllocSize(v int) Option {
if v < 1 {
panic("BucketsMapPreAllocSize: param is illegal")
}
return func(o *options) {
o.bucketsMapPreAllocSize = v
}
}
// CleanInterval cleans up expired object cycles.
func CleanInterval(v int) Option {
if v < 1 {
panic("CleanInterval: param is illegal")
}
return func(o *options) {
o.cleanInterval = v
}
}