mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 06:16:58 +00:00
wip: add fileCache back
This commit is contained in:
parent
9626d3a8a0
commit
8dac935cd8
2 changed files with 127 additions and 52 deletions
|
@ -1,24 +1,48 @@
|
|||
package gitea
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FileResponse struct {
|
||||
Exists bool
|
||||
ETag []byte
|
||||
MimeType string
|
||||
Body []byte
|
||||
Exists bool
|
||||
IsSymlink bool
|
||||
ETag string
|
||||
MimeType string
|
||||
Body []byte
|
||||
}
|
||||
|
||||
func (f FileResponse) IsEmpty() bool {
|
||||
return len(f.Body) != 0
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
type BranchTimestamp struct {
|
||||
Branch string
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
var (
|
||||
const (
|
||||
// defaultBranchCacheTimeout specifies the timeout for the default branch cache. It can be quite long.
|
||||
defaultBranchCacheTimeout = 15 * time.Minute
|
||||
|
||||
|
@ -30,8 +54,8 @@ var (
|
|||
// 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
|
||||
// fileCacheTimeout = 5 * time.Minute
|
||||
fileCacheTimeout = 5 * time.Minute
|
||||
|
||||
// fileCacheSizeLimit limits the maximum file size that will be cached, and is set to 1 MB by default.
|
||||
// fileCacheSizeLimit = 1024 * 1024
|
||||
fileCacheSizeLimit = int64(1024 * 1024)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue