@@ -13,7 +13,6 @@ import (
13
13
14
14
// Cache represents cache settings
15
15
type Cache struct {
16
- Enabled bool
17
16
Adapter string
18
17
Interval int
19
18
Conn string
@@ -26,30 +25,21 @@ var (
26
25
Cache
27
26
28
27
LastCommit struct {
29
- Cache
30
- UseSeperateCache bool
31
- CommitsCount int64
28
+ TTL time.Duration `ini:"ITEM_TTL"`
29
+ CommitsCount int64
32
30
} `ini:"cache.last_commit"`
33
31
}{
34
32
Cache : Cache {
35
- Enabled : true ,
36
33
Adapter : "memory" ,
37
34
Interval : 60 ,
38
35
TTL : 16 * time .Hour ,
39
36
},
40
37
LastCommit : struct {
41
- Cache
42
- UseSeperateCache bool
43
- CommitsCount int64
38
+ TTL time.Duration `ini:"ITEM_TTL"`
39
+ CommitsCount int64
44
40
}{
45
- Cache : Cache {
46
- Enabled : true ,
47
- Adapter : "memory" ,
48
- Interval : 60 ,
49
- TTL : 86400 * time .Hour ,
50
- },
51
- UseSeperateCache : false ,
52
- CommitsCount : 1000 ,
41
+ TTL : 16 * time .Hour ,
42
+ CommitsCount : 1000 ,
53
43
},
54
44
}
55
45
)
@@ -66,34 +56,23 @@ func newCacheService() {
66
56
case "redis" , "memcache" :
67
57
CacheService .Conn = strings .Trim (sec .Key ("HOST" ).String (), "\" " )
68
58
case "" : // disable cache
69
- CacheService .Enabled = false
59
+ CacheService .TTL = 0
70
60
default :
71
61
log .Fatal ("Unknown cache adapter: %s" , CacheService .Adapter )
72
62
}
73
63
74
- if CacheService .Enabled {
64
+ if CacheService .TTL > 0 {
75
65
log .Info ("Cache Service Enabled" )
76
66
}
77
67
78
68
sec = Cfg .Section ("cache.last_commit" )
79
- if ! CacheService .LastCommit .UseSeperateCache {
80
- CacheService .LastCommit .Cache = CacheService .Cache
81
- } else {
82
- CacheService .LastCommit .Adapter = sec .Key ("ADAPTER" ).In ("memory" , []string {"memory" , "redis" , "memcache" })
83
- switch CacheService .LastCommit .Adapter {
84
- case "memory" :
85
- case "redis" , "memcache" :
86
- CacheService .LastCommit .Conn = strings .Trim (sec .Key ("HOST" ).String (), "\" " )
87
- case "" : // disable cache
88
- CacheService .LastCommit .Enabled = false
89
- default :
90
- log .Fatal ("Unknown cache.last_commit adapter: %s" , CacheService .LastCommit .Adapter )
91
- }
69
+ if CacheService .TTL == 0 {
70
+ CacheService .LastCommit .TTL = 0
92
71
}
93
72
94
73
CacheService .LastCommit .CommitsCount = sec .Key ("COMMITS_COUNT" ).MustInt64 (1000 )
95
74
96
- if CacheService .LastCommit .Enabled {
75
+ if CacheService .LastCommit .TTL > 0 {
97
76
log .Info ("Last Commit Cache Service Enabled" )
98
77
}
99
78
}
0 commit comments