mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-05-15 09:47:09 +02:00
Add redis for caching, first try during a train ride so expect it to not be working yet
This commit is contained in:
parent
b8b9886ee1
commit
5b6eecc75f
12 changed files with 149 additions and 32 deletions
|
@ -1,6 +1,7 @@
|
|||
package upstream
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -29,7 +30,12 @@ func (o *Options) getRedirects(giteaClient *gitea.Client, redirectsCache cache.I
|
|||
|
||||
// Check for cached redirects
|
||||
if cachedValue, ok := redirectsCache.Get(cacheKey); ok {
|
||||
redirects = cachedValue.([]Redirect)
|
||||
redirects := []Redirect{}
|
||||
err := json.Unmarshal([]byte(cachedValue), redirects)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("could not parse redirects for key %s", cacheKey)
|
||||
// It's okay to continue, the array stays empty.
|
||||
}
|
||||
} else {
|
||||
// Get _redirects file and parse
|
||||
body, err := giteaClient.GiteaRawContent(o.TargetOwner, o.TargetRepo, o.TargetBranch, redirectsConfig)
|
||||
|
@ -58,7 +64,12 @@ func (o *Options) getRedirects(giteaClient *gitea.Client, redirectsCache cache.I
|
|||
})
|
||||
}
|
||||
}
|
||||
_ = redirectsCache.Set(cacheKey, redirects, redirectsCacheTimeout)
|
||||
redirectsJson, err := json.Marshal(redirects)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("could not store redirects for key %s", cacheKey)
|
||||
} else {
|
||||
_ = redirectsCache.Set(cacheKey, string(redirectsJson), redirectsCacheTimeout)
|
||||
}
|
||||
}
|
||||
return redirects
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue