diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-01-02 00:06:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-02 00:06:52 +0800 |
commit | a1c30740bb04ed55905415dcd195ee9fb97547de (patch) | |
tree | 60dd79afebadd9d092b84d790a1cf4678c4619d4 /modules/cache | |
parent | 0f4e1b9ac66b8ffa0083a5a2516e4710393bb0da (diff) | |
download | gitea-a1c30740bb04ed55905415dcd195ee9fb97547de.tar.gz gitea-a1c30740bb04ed55905415dcd195ee9fb97547de.zip |
Fix get system setting bug when enabled redis cache (#22295)
Fix #22281
In #21621 , `Get[V]` and `Set[V]` has been introduced, so that cache
value will be `*Setting`. For memory cache it's OK. But for redis cache,
it can only store `string` for the current implementation. This PR
revert some of changes of that and just store or return a `string` for
system setting.
Diffstat (limited to 'modules/cache')
-rw-r--r-- | modules/cache/cache.go | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/modules/cache/cache.go b/modules/cache/cache.go index 2e7d5bb603..edaf483135 100644 --- a/modules/cache/cache.go +++ b/modules/cache/cache.go @@ -45,39 +45,6 @@ func GetCache() mc.Cache { return conn } -// Get returns the key value from cache with callback when no key exists in cache -func Get[V interface{}](key string, getFunc func() (V, error)) (V, error) { - if conn == nil || setting.CacheService.TTL == 0 { - return getFunc() - } - - cached := conn.Get(key) - if value, ok := cached.(V); ok { - return value, nil - } - - value, err := getFunc() - if err != nil { - return value, err - } - - return value, conn.Put(key, value, setting.CacheService.TTLSeconds()) -} - -// Set updates and returns the key value in the cache with callback. The old value is only removed if the updateFunc() is successful -func Set[V interface{}](key string, valueFunc func() (V, error)) (V, error) { - if conn == nil || setting.CacheService.TTL == 0 { - return valueFunc() - } - - value, err := valueFunc() - if err != nil { - return value, err - } - - return value, conn.Put(key, value, setting.CacheService.TTLSeconds()) -} - // GetString returns the key value from cache with callback when no key exists in cache func GetString(key string, getFunc func() (string, error)) (string, error) { if conn == nil || setting.CacheService.TTL == 0 { |