Optimize caching, speed up imports

This commit is contained in:
Mukhtar Akere
2025-05-08 02:15:46 +01:00
parent 0deb88e265
commit 57de04b164
7 changed files with 170 additions and 98 deletions

View File

@@ -5,6 +5,7 @@ import (
"net/url"
"os"
"strings"
"time"
)
// getName: Returns the torrent name and filename from the path
@@ -27,3 +28,14 @@ func isValidURL(str string) bool {
// A valid URL should parse without error, and have a non-empty scheme and host.
return err == nil && u.Scheme != "" && u.Host != ""
}
// Determine TTL based on the requested folder:
// - If the path is exactly the parent folder (which changes frequently),
// use a short TTL.
// - Otherwise, for deeper (torrent folder) paths, use a longer TTL.
func (h *Handler) getCacheTTL(urlPath string) time.Duration {
if h.isParentPath(urlPath) {
return 30 * time.Second // Short TTL for parent folders
}
return 2 * time.Minute // Longer TTL for other paths
}