Skip to content

Commit

Permalink
Page cache (#489)
Browse files Browse the repository at this point in the history
* Add cache control headers for root path

* Remove unnecessary logging and simplify cache header logic
  • Loading branch information
swuecho authored Jul 6, 2024
1 parent 3b8ac54 commit 3346eb8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions api/file_upload_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"strconv"

Expand Down Expand Up @@ -126,8 +125,7 @@ func (h *ChatFileHandler) ChatFilesBySessionUUID(w http.ResponseWriter, r *http.
return
}
w.WriteHeader(http.StatusOK)
log.Printf("chatFiles: %+v", chatFiles)
// why this?

if len(chatFiles) == 0 {
w.Write([]byte("[]"))
return
Expand Down
4 changes: 2 additions & 2 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ func main() {

// Set cache headers for static/assets files
cacheHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.URL.Path)
if strings.HasPrefix(r.URL.Path, "assets/") {
w.Header().Set("Cache-Control", "max-age=31536000") // 1 year
} else if r.URL.Path == "/index.html" {
// Set no cache headers for index.html
} else {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
Expand Down

0 comments on commit 3346eb8

Please sign in to comment.