Add caching

This commit is contained in:
Ben Sarmiento
2023-10-22 13:29:41 +02:00
parent c789ebc96d
commit 6eccba394c
9 changed files with 74 additions and 55 deletions

View File

@@ -6,17 +6,18 @@ import (
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/hashicorp/golang-lru/v2/expirable"
)
// Router creates a WebDAV router
func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentManager) {
func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentManager, cache *expirable.LRU[string, string]) {
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PROPFIND":
HandlePropfindRequest(w, r, t, c)
HandlePropfindRequest(w, r, t, c, cache)
case http.MethodGet:
HandleGetRequest(w, r, t, c)
HandleGetRequest(w, r, t, c, cache)
case http.MethodOptions:
w.WriteHeader(http.StatusOK)