mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
use strings.HasPrefix for shortTTLPaths
This commit is contained in:
+5
-3
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user