diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-12-06 00:24:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-06 00:24:57 +0800 |
commit | 11d519b38541fe4c05b11e15be6c90ae5ae37f22 (patch) | |
tree | 30974f13f55724f3923b915a1819f362a8229794 /modules | |
parent | b4a32afec1fa1989b0060ae31347e583cfb51c13 (diff) | |
download | gitea-11d519b38541fe4c05b11e15be6c90ae5ae37f22.tar.gz gitea-11d519b38541fe4c05b11e15be6c90ae5ae37f22.zip |
Test cache during init (#17852)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/cache/cache.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/cache/cache.go b/modules/cache/cache.go index 3a2732c343..e7630638bf 100644 --- a/modules/cache/cache.go +++ b/modules/cache/cache.go @@ -8,6 +8,7 @@ import ( "fmt" "strconv" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" mc "gitea.com/go-chi/cache" @@ -35,6 +36,20 @@ func NewContext() error { if conn, err = newCache(setting.CacheService.Cache); err != nil { return err } + const testKey = "__gitea_cache_test" + const testVal = "test-value" + if err = conn.Put(testKey, testVal, 10); err != nil { + return err + } + val := conn.Get(testKey) + if valStr, ok := val.(string); !ok || valStr != testVal { + // If the cache is full, the Get may not read the expected value stored by Put. + // Since we have checked that Put can success, so we just show a warning here, do not return an error to panic. + log.Warn("cache (adapter:%s, config:%s) doesn't seem to work correctly, set test value '%v' but get '%v'", + setting.CacheService.Cache.Adapter, setting.CacheService.Cache.Conn, + testVal, val, + ) + } } return err |