From 12bc642de5d56f06e203324bc9570b9f3a848965 Mon Sep 17 00:00:00 2001 From: "Diogo Franco (Kovensky)" Date: Tue, 16 Jul 2013 14:05:13 -0300 Subject: [PATCH] anidb: Cache finished anime for longer Once they've finished airing, it's more unlikely they'll get updates. We only consider they as finished if they were cached more than one AnimeCacheDuration after the end though. --- animecache.go | 11 +++++++++-- misc.go | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/animecache.go b/animecache.go index fd2d7f3..25624fb 100644 --- a/animecache.go +++ b/animecache.go @@ -26,10 +26,17 @@ func (a *Anime) IsStale() bool { if a == nil { return true } + now := time.Now() + diff := now.Sub(a.Cached) if a.Incomplete { - return time.Now().Sub(a.Cached) > AnimeIncompleteCacheDuration + return diff > AnimeIncompleteCacheDuration } - return time.Now().Sub(a.Cached) > AnimeCacheDuration + + // If the anime ended, and more than AnimeCacheDuration time ago at that + if !a.EndDate.IsZero() && now.After(a.EndDate.Add(AnimeCacheDuration)) { + return diff > FinishedAnimeCacheDuration + } + return diff > AnimeCacheDuration } // Unique Anime IDentifier. diff --git a/misc.go b/misc.go index 22a010c..b6d9db8 100644 --- a/misc.go +++ b/misc.go @@ -15,6 +15,10 @@ var ( GroupCacheDuration = 4 * DefaultCacheDuration // They don't change that often. FileCacheDuration = 8 * DefaultCacheDuration // These change even less often. + // Used for anime that have already finished airing. + // It's unlikely that they get any important updates. + FinishedAnimeCacheDuration = 4 * AnimeCacheDuration + // Used when a request uses a non-existing key (AID, ed2k+size, etc) InvalidKeyCacheDuration = 1 * time.Hour -- 2.44.0