55package cache
66
77import (
8- "errors"
98 "fmt"
109 "strconv"
1110
12- "code.gitea.io/gitea/modules/log"
1311 "code.gitea.io/gitea/modules/setting"
1412
1513 mc "gitea.com/go-chi/cache"
@@ -35,37 +33,14 @@ func NewContext() error {
3533 if conn , err = newCache (setting .CacheService .Cache ); err != nil {
3634 return err
3735 }
38- if err = Ping (); err != nil {
36+ if err = conn . Ping (); err != nil {
3937 return err
4038 }
4139 }
4240
4341 return err
4442}
4543
46- // Ping checks if the cache service works or not, it not, it returns an error
47- func Ping () error {
48- if conn == nil {
49- return errors .New ("cache not available" )
50- }
51- var err error
52- const testKey = "__gitea_cache_test"
53- const testVal = "test-value"
54- if err = conn .Put (testKey , testVal , 10 ); err != nil {
55- return err
56- }
57- val := conn .Get (testKey )
58- if valStr , ok := val .(string ); ! ok || valStr != testVal {
59- // If the cache is full, the Get may not read the expected value stored by Put.
60- // Since we have checked that Put can success, so we just show a warning here, do not return an error to panic.
61- log .Warn ("cache (adapter:%s, config:%s) doesn't seem to work correctly, set test value '%v' but get '%v'" ,
62- setting .CacheService .Cache .Adapter , setting .CacheService .Cache .Conn ,
63- testVal , val ,
64- )
65- }
66- return nil
67- }
68-
6944// GetCache returns the currently configured cache
7045func GetCache () mc.Cache {
7146 return conn
0 commit comments