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.
This commit is contained in:
Frank Denis 2018-01-18 22:23:40 +01:00
parent 6c67739b56
commit c4bd6eb9f0
1 changed files with 4 additions and 3 deletions

View File

@ -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