Skip to content

Commit 11d519b

Browse files
authored
Test cache during init (#17852)
1 parent b4a32af commit 11d519b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

modules/cache/cache.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"strconv"
1010

11+
"code.gitea.io/gitea/modules/log"
1112
"code.gitea.io/gitea/modules/setting"
1213

1314
mc "gitea.com/go-chi/cache"
@@ -35,6 +36,20 @@ func NewContext() error {
3536
if conn, err = newCache(setting.CacheService.Cache); err != nil {
3637
return err
3738
}
39+
const testKey = "__gitea_cache_test"
40+
const testVal = "test-value"
41+
if err = conn.Put(testKey, testVal, 10); err != nil {
42+
return err
43+
}
44+
val := conn.Get(testKey)
45+
if valStr, ok := val.(string); !ok || valStr != testVal {
46+
// If the cache is full, the Get may not read the expected value stored by Put.
47+
// Since we have checked that Put can success, so we just show a warning here, do not return an error to panic.
48+
log.Warn("cache (adapter:%s, config:%s) doesn't seem to work correctly, set test value '%v' but get '%v'",
49+
setting.CacheService.Cache.Adapter, setting.CacheService.Cache.Conn,
50+
testVal, val,
51+
)
52+
}
3853
}
3954

4055
return err

0 commit comments

Comments
 (0)