zhangzengfei
2021-11-11 81e30f0a90ce024f6dea87d79ea8967780109843
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
package boltcache
 
import (
    "fmt"
    "time"
)
 
type Config struct {
    path                string
    capacity            int             //单个桶最多放多少条数据
    bucketLimit         int             //保留的bucket的最大个数
    keepDays            int             //最多保留多少天的数据
 
    cleanDuration         time.Duration   //清理周期
 
    logPrint func(v ...interface{})
}
 
func NewDefaultConfig() *Config {
    return &Config{
        path:          "./push.db",
        capacity:      50,
        bucketLimit:   10,
        keepDays:      1,
        cleanDuration: 10 * time.Second,
        logPrint: func(v ...interface{}) {
            fmt.Println(v...)
        },
    }
}
 
func NewConfig(path string, capacity int, bucketLimit int, keepDays int,logPrint func(v ...interface{})) *Config {
    return &Config{
        path:          path,
        capacity:      capacity,
        bucketLimit:   bucketLimit,
        keepDays:      keepDays,
        cleanDuration: time.Second * 10,
        logPrint:      logPrint,
    }
}