pages-server/server/gitea/cache.go

62 lines
1.6 KiB
Go
Raw Normal View History

package gitea
2022-09-18 19:02:55 +00:00
import (
"net/http"
"time"
)
2022-07-27 13:39:46 +00:00
type FileResponse struct {
2022-09-18 19:02:55 +00:00
Exists bool
IsSymlink bool
ETag string
MimeType string
Body []byte
}
func (f FileResponse) IsEmpty() bool {
return len(f.Body) != 0
}
2022-07-27 13:39:46 +00:00
2022-09-18 19:02:55 +00:00
func (f FileResponse) createHttpResponse() *http.Response {
resp := &http.Response{
Header: make(http.Header),
}
if f.Exists {
resp.StatusCode = http.StatusOK
} else {
resp.StatusCode = http.StatusNotFound
}
if f.IsSymlink {
resp.Header.Set(giteaObjectTypeHeader, objTypeSymlink)
}
resp.Header.Set(eTagHeader, f.ETag)
resp.Header.Set(contentTypeHeader, f.MimeType)
return resp
}
2022-07-27 13:39:46 +00:00
type BranchTimestamp struct {
Branch string
Timestamp time.Time
}
2022-09-18 19:02:55 +00:00
const (
2022-07-27 13:39:46 +00:00
// defaultBranchCacheTimeout specifies the timeout for the default branch cache. It can be quite long.
defaultBranchCacheTimeout = 15 * time.Minute
// branchExistenceCacheTimeout specifies the timeout for the branch timestamp & existence cache. It should be shorter
// than fileCacheTimeout, as that gets invalidated if the branch timestamp has changed. That way, repo changes will be
// picked up faster, while still allowing the content to be cached longer if nothing changes.
branchExistenceCacheTimeout = 5 * time.Minute
2022-07-27 15:25:08 +00:00
// fileCacheTimeout specifies the timeout for the file content cache - you might want to make this quite long, depending
// on your available memory.
// TODO: move as option into cache interface
2022-09-18 19:02:55 +00:00
fileCacheTimeout = 5 * time.Minute
2022-07-27 15:25:08 +00:00
// fileCacheSizeLimit limits the maximum file size that will be cached, and is set to 1 MB by default.
2022-09-18 19:02:55 +00:00
fileCacheSizeLimit = int64(1024 * 1024)
2022-07-27 13:39:46 +00:00
)