mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-25 21:14:20 +01:00
Test cache during init (#17852)
This commit is contained in:
parent
b4a32afec1
commit
11d519b385
1 changed files with 15 additions and 0 deletions
15
modules/cache/cache.go
vendored
15
modules/cache/cache.go
vendored
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
mc "gitea.com/go-chi/cache"
|
mc "gitea.com/go-chi/cache"
|
||||||
|
@ -35,6 +36,20 @@ func NewContext() error {
|
||||||
if conn, err = newCache(setting.CacheService.Cache); err != nil {
|
if conn, err = newCache(setting.CacheService.Cache); err != nil {
|
||||||
return err
|
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
|
return err
|
||||||
|
|
Loading…
Reference in a new issue