-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
74 lines (62 loc) · 1.98 KB
/
types.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
70
71
72
73
74
package jac
import (
"os"
"sync"
"time"
)
// external data types
// Default options are
// ExpirationTime: 0,
// IntervalCompacting: 1440 * 60,
// InternalBuffering: 10,
// LoadDelayMs: 10,
// MaximumAge: 5 * 60,
type Options struct {
ExpirationTime int // Expiration time is seconds
IntervalCompacting int // Cache working files compacting interval in seconds (values smaller than 60s will be defaulted to 60s)
InternalBuffering int // Buffering length to decouple the in-memory cache from the disk processes. Bigger numbers improve cache speed at expenses of system crash resistance
LoadDelayMs int // Regulates the start-up delay. Smaller numbers improves start-up time at costs of possible loss of persistence
MaximumAge int64 // Maximum age (in s) of a back-up file (.rec) or working file (.data) for it to be used to initialise the cache
WorkingFolder string // folder for working files (.data). File contain the entire cache in a readable. Altering the files only affects the initial cache load not its operation
RecoveryFolder string // folder for back-up files (.rec)
}
type Item struct {
Object interface{}
Expiration int64
}
type FileData struct {
Key string `json:"key"`
Value string `json:"value"`
}
type Bucket struct {
name string
bucket *bucketInternalPtr
file *os.File
writer chan backupData
cr chan interface{}
}
// internal data types
type bucketInternalPtr struct {
*bucketInternal
}
type bucketInternal struct {
defaultExpiration time.Duration
items map[string]Item
mu sync.RWMutex
onEvicted func(string, interface{})
janitor *janitor
}
type keyAndValue struct {
key string
value interface{}
}
type janitor struct {
Interval time.Duration
stop chan bool
}
type backupData struct {
data [2]string
c *bucketInternalPtr // when not nil a file compaction is requested
file *os.File
}
type updateFunc func(k, v string) (string, string)