From 7d19f8af71b6c488313facac3e5f4af247f8b9a8 Mon Sep 17 00:00:00 2001 From: stefanodvx <69367859+stefanodvx@users.noreply.github.com> Date: Thu, 17 Apr 2025 01:53:10 +0200 Subject: [PATCH] misc: cache for cookies --- util/misc.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/misc.go b/util/misc.go index ada02f1..0abb4c6 100644 --- a/util/misc.go +++ b/util/misc.go @@ -15,6 +15,8 @@ import ( "github.com/aki237/nscjar" ) +var cookiesCache = make(map[string][]*http.Cookie) + func GetLocationURL( url string, userAgent string, @@ -88,6 +90,10 @@ func GetLastError(err error) error { } func ParseCookieFile(fileName string) ([]*http.Cookie, error) { + cachedCookies, ok := cookiesCache[fileName] + if ok { + return cachedCookies, nil + } cookiePath := filepath.Join("cookies", fileName) cookieFile, err := os.Open(cookiePath) if err != nil { @@ -100,6 +106,7 @@ func ParseCookieFile(fileName string) ([]*http.Cookie, error) { if err != nil { return nil, fmt.Errorf("failed to parse cookie file: %w", err) } + cookiesCache[fileName] = cookies return cookies, nil }