-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.go
69 lines (60 loc) · 1.45 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package cachestore
import "time"
func ApplyOptions(opts ...StoreOptions) StoreOptions {
if len(opts) == 0 {
return StoreOptions{
Apply: func(opts *StoreOptions) {},
}
}
so := opts[0]
for _, opt := range opts {
opt.Apply(&so)
}
return so
}
func WithDefaultKeyExpiry(keyExpiry time.Duration) StoreOptions {
return StoreOptions{
Apply: func(opts *StoreOptions) {
opts.DefaultKeyExpiry = keyExpiry
},
}
}
func WithLockExpiry(lockExpiry time.Duration) StoreOptions {
return StoreOptions{
Apply: func(opts *StoreOptions) {
opts.LockExpiry = lockExpiry
},
}
}
func WithLockRetryTimeout(retryTimeout time.Duration) StoreOptions {
return StoreOptions{
Apply: func(opts *StoreOptions) {
opts.LockRetryTimeout = retryTimeout
},
}
}
func WithLockRetryDelay(minDelay, maxDelay time.Duration) StoreOptions {
return StoreOptions{
Apply: func(opts *StoreOptions) {
opts.LockMinRetryDelay = minDelay
opts.LockMaxRetryDelay = maxDelay
},
}
}
// NOTE: currently not in use, but we could add it
// func WithDefaultKeyPrefix(keyPrefix string) StoreOptions {
// return StoreOptions{
// Apply: func(opts *StoreOptions) {
// opts.DefaultKeyPrefix = keyPrefix
// },
// }
// }
type StoreOptions struct {
Apply func(*StoreOptions)
DefaultKeyExpiry time.Duration
// DefaultKeyPrefix string
LockExpiry time.Duration
LockRetryTimeout time.Duration
LockMinRetryDelay time.Duration
LockMaxRetryDelay time.Duration
}