From c4bd6eb9f037a222ce02840531cc529beae7c4f9 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 18 Jan 2018 22:23:40 +0100 Subject: [PATCH] Make the distinction between a usable cache and a hot cache A hot cache is still fresh. A usable cache exists, and can act as a backup solution is we can't fetch a list from a remote server. --- dnscrypt-proxy/sources.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dnscrypt-proxy/sources.go b/dnscrypt-proxy/sources.go index ff435eaa..57d39f2e 100644 --- a/dnscrypt-proxy/sources.go +++ b/dnscrypt-proxy/sources.go @@ -34,15 +34,16 @@ func fetchFromCache(cacheFile string) ([]byte, error) { func fetchWithCache(url string, cacheFile string, refreshDelay time.Duration) (in string, cached bool, err error) { var bin []byte - cached, usableCache := false, false + cached, usableCache, hotCache := false, false, false fi, err := os.Stat(cacheFile) if err == nil { + usableCache = true elapsed := time.Since(fi.ModTime()) if elapsed < refreshDelay && elapsed >= 0 { - usableCache = true + hotCache = true } } - if usableCache { + if hotCache { bin, err = fetchFromCache(cacheFile) if err == nil { cached = true