-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
59 lines (45 loc) · 1.05 KB
/
options.go
File metadata and controls
59 lines (45 loc) · 1.05 KB
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
package disklru
const (
NS = 1000000000
)
// Control the behavious of the cache
type Options struct {
// Path to the sqlite cache file.
Filename string
// Clear the file on start
ClearOnStart bool
// The maximum number of items to keep in cache
MaxSize int
// How long to keep items in cache
MaxExpirySec int
// Should expiry time be updated on access?
UpdateExpiryOnAccess bool
// How often to run the housekeeping thread, negative number
// disables automatic housekeeping.
HouseKeepPeriodSec int64
// The clock is used to control time in tests etc.
Clock Clock
// Set for explicit debugging.
DEBUG bool
}
// Set some reasonable defaults.
func (self *Options) UpdateDefaults() {
if self.Clock == nil {
self.Clock = &RealClock{}
}
if self.MaxExpirySec == 0 {
self.MaxExpirySec = 60
}
if self.MaxSize == 0 {
self.MaxSize = 1000
}
// Every minute
if self.HouseKeepPeriodSec == 0 {
self.HouseKeepPeriodSec = 60
}
}
type Clock interface {
// Returns the time in nanosec since the epoch
// e.g. time.Now().UnixNano()
Now() int64
}