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:
parent
6c67739b56
commit
c4bd6eb9f0
|
@ -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) {
|
func fetchWithCache(url string, cacheFile string, refreshDelay time.Duration) (in string, cached bool, err error) {
|
||||||
var bin []byte
|
var bin []byte
|
||||||
cached, usableCache := false, false
|
cached, usableCache, hotCache := false, false, false
|
||||||
fi, err := os.Stat(cacheFile)
|
fi, err := os.Stat(cacheFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
usableCache = true
|
||||||
elapsed := time.Since(fi.ModTime())
|
elapsed := time.Since(fi.ModTime())
|
||||||
if elapsed < refreshDelay && elapsed >= 0 {
|
if elapsed < refreshDelay && elapsed >= 0 {
|
||||||
usableCache = true
|
hotCache = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if usableCache {
|
if hotCache {
|
||||||
bin, err = fetchFromCache(cacheFile)
|
bin, err = fetchFromCache(cacheFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cached = true
|
cached = true
|
||||||
|
|
Loading…
Reference in New Issue