diff --git a/core/requests.go b/core/requests.go index 67cde11..c6f5c41 100644 --- a/core/requests.go +++ b/core/requests.go @@ -60,14 +60,15 @@ var ( cacheSeed uint64 cache *lru.Cache - // shortTTLPaths lists URI paths that require a shorter TTL for their cached responses. + // shortTTLPaths lists API endpoints that require a shorter TTL for their cached responses. shortTTLPaths = []string{ "/ajax/discovery/artworks", "/ajax/discovery/novels", "/ajax/illust/new", } - // excludedCachePaths lists API endpoints that should *never* be cached, regardless of any other factors. + // excludedCachePaths lists API endpoints for which responses should *never* be cached, + // regardless of any other factors. excludedCachePaths = []string{ "/ranking.php", } @@ -198,6 +199,7 @@ func manageCaching(rawURL, userToken string, headers http.Header, response *Simp ttl := config.GlobalConfig.CacheTTL parsedURL, err := url.Parse(rawURL) if err != nil { + // Handle parsing error by returning the response without caching return CachingResult{ Response: response, FromCache: false, @@ -205,7 +207,7 @@ func manageCaching(rawURL, userToken string, headers http.Header, response *Simp } urlPath := path.Clean(parsedURL.Path) for _, shortPath := range shortTTLPaths { - if urlPath == shortPath { + if strings.HasPrefix(urlPath, shortPath) { ttl = config.GlobalConfig.CacheShortTTL break }