5
5
package cache
6
6
7
7
import (
8
- "time"
9
-
10
8
"code.gitea.io/gitea/modules/setting"
11
9
12
10
mc "github.com/go-macaron/cache"
@@ -31,7 +29,7 @@ func NewContext() error {
31
29
32
30
// GetInt returns key value from cache with callback when no key exists in cache
33
31
func GetInt (key string , getFunc func () (int , error )) (int , error ) {
34
- if conn == nil {
32
+ if conn == nil || setting . CacheService . TTL == 0 {
35
33
return getFunc ()
36
34
}
37
35
if ! conn .IsExist (key ) {
@@ -42,14 +40,14 @@ func GetInt(key string, getFunc func() (int, error)) (int, error) {
42
40
if value , err = getFunc (); err != nil {
43
41
return value , err
44
42
}
45
- conn .Put (key , value , int64 (time . Hour .Seconds ()))
43
+ conn .Put (key , value , int64 (setting . CacheService . TTL .Seconds ()))
46
44
}
47
45
return conn .Get (key ).(int ), nil
48
46
}
49
47
50
48
// GetInt64 returns key value from cache with callback when no key exists in cache
51
49
func GetInt64 (key string , getFunc func () (int64 , error )) (int64 , error ) {
52
- if conn == nil {
50
+ if conn == nil || setting . CacheService . TTL == 0 {
53
51
return getFunc ()
54
52
}
55
53
if ! conn .IsExist (key ) {
@@ -60,7 +58,7 @@ func GetInt64(key string, getFunc func() (int64, error)) (int64, error) {
60
58
if value , err = getFunc (); err != nil {
61
59
return value , err
62
60
}
63
- conn .Put (key , value , int64 (time . Hour .Seconds ()))
61
+ conn .Put (key , value , int64 (setting . CacheService . TTL .Seconds ()))
64
62
}
65
63
return conn .Get (key ).(int64 ), nil
66
64
}
0 commit comments