use strings.HasPrefix for shortTTLPaths

This commit is contained in:
perennial
2024-10-17 20:40:52 +11:00
parent 54dcde38af
commit 0952dda06a
+5 -3
View File
@@ -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
}