mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-19 11:36:57 +00:00
Move redis config to CacheConfig struct, add cache prefixes & trace logging
This commit is contained in:
parent
e1a22d5f4c
commit
46c8daacba
7 changed files with 45 additions and 30 deletions
|
@ -117,8 +117,7 @@ func (client *Client) ServeRawContent(targetOwner, targetRepo, ref, resource str
|
|||
// handle if cache entry exist
|
||||
if cacheMetadata, ok := client.responseCache.Get(cacheKey + "|Metadata"); ok {
|
||||
cache := FileResponseFromMetadataString(string(cacheMetadata))
|
||||
cacheBodyString, _ := client.responseCache.Get(cacheKey + "|Body")
|
||||
cache.Body = []byte(cacheBodyString)
|
||||
cache.Body, _ = client.responseCache.Get(cacheKey + "|Body")
|
||||
// TODO: don't grab the content from the cache if the ETag matches?!
|
||||
|
||||
cachedHeader, cachedStatusCode := cache.createHttpResponse(cacheKey)
|
||||
|
@ -136,8 +135,9 @@ func (client *Client) ServeRawContent(targetOwner, targetRepo, ref, resource str
|
|||
log.Debug().Msg("[cache] is empty")
|
||||
// TODO: empty files aren't cached anyways; but when closing the issue please make sure that a missing body cache key is also handled correctly.
|
||||
}
|
||||
}
|
||||
} // TODO: handle missing pages if they redirect to a index.html
|
||||
}
|
||||
// TODO: metadata not written, is close ever called?
|
||||
log.Trace().Msg("file not in cache")
|
||||
// not in cache, open reader via gitea api
|
||||
reader, resp, err := client.sdkClient.GetFileReader(targetOwner, targetRepo, ref, resource, client.supportLFS)
|
||||
|
@ -284,12 +284,12 @@ func (client *Client) GiteaCheckIfOwnerExists(owner string) (bool, error) {
|
|||
cacheKey := fmt.Sprintf("%s/%s", ownerExistenceKeyPrefix, owner)
|
||||
|
||||
if exist, ok := client.responseCache.Get(cacheKey); ok && exist != nil {
|
||||
return exist.(bool), nil
|
||||
return string(exist) == "true", nil
|
||||
}
|
||||
|
||||
_, resp, err := client.sdkClient.GetUserInfo(owner)
|
||||
if resp.StatusCode == http.StatusOK && err == nil {
|
||||
if err := client.responseCache.Set(cacheKey, true, ownerExistenceCacheTimeout); err != nil {
|
||||
if err := client.responseCache.Set(cacheKey, []byte("true"), ownerExistenceCacheTimeout); err != nil {
|
||||
log.Error().Err(err).Msg("[cache] error on cache write")
|
||||
}
|
||||
return true, nil
|
||||
|
@ -299,14 +299,14 @@ func (client *Client) GiteaCheckIfOwnerExists(owner string) (bool, error) {
|
|||
|
||||
_, resp, err = client.sdkClient.GetOrg(owner)
|
||||
if resp.StatusCode == http.StatusOK && err == nil {
|
||||
if err := client.responseCache.Set(cacheKey, true, ownerExistenceCacheTimeout); err != nil {
|
||||
if err := client.responseCache.Set(cacheKey, []byte("true"), ownerExistenceCacheTimeout); err != nil {
|
||||
log.Error().Err(err).Msg("[cache] error on cache write")
|
||||
}
|
||||
return true, nil
|
||||
} else if resp.StatusCode != http.StatusNotFound {
|
||||
return false, err
|
||||
}
|
||||
if err := client.responseCache.Set(cacheKey, false, ownerExistenceCacheTimeout); err != nil {
|
||||
if err := client.responseCache.Set(cacheKey, []byte("false"), ownerExistenceCacheTimeout); err != nil {
|
||||
log.Error().Err(err).Msg("[cache] error on cache write")
|
||||
}
|
||||
return false, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue