more efficient caching

This commit is contained in:
Ben Sarmiento
2023-10-22 14:25:28 +02:00
parent 6eccba394c
commit 16d6bf4f81
3 changed files with 27 additions and 23 deletions

View File

@@ -16,6 +16,8 @@ import (
func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface, cache *expirable.LRU[string, string]) {
requestPath := path.Clean(r.URL.Path)
requestPath = strings.Trim(requestPath, "/")
if data, exists := cache.Get(requestPath); exists {
w.Header().Set("Content-Type", "text/xml; charset=\"utf-8\"")
w.WriteHeader(http.StatusMultiStatus)
@@ -26,14 +28,14 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To
var output []byte
var err error
filteredSegments := strings.Split(strings.Trim(requestPath, "/"), "/")
filteredSegments := strings.Split(requestPath, "/")
switch len(filteredSegments) {
case 0:
switch {
case len(filteredSegments) == 1 && filteredSegments[0] == "":
output, err = handleRoot(w, r, c)
case 1:
case len(filteredSegments) == 1:
output, err = handleListOfTorrents(requestPath, w, r, t, c)
case 2:
case len(filteredSegments) == 2:
output, err = handleSingleTorrent(requestPath, w, r, t)
default:
writeHTTPError(w, "Not Found", http.StatusNotFound)