Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'cache/filecache/filecache.go')
-rw-r--r--cache/filecache/filecache.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/cache/filecache/filecache.go b/cache/filecache/filecache.go
index c6ea02681..da0a90d57 100644
--- a/cache/filecache/filecache.go
+++ b/cache/filecache/filecache.go
@@ -36,8 +36,9 @@ import (
type Cache struct {
Fs afero.Fs
- // Max age in seconds.
- maxAge int
+ // Max age for items in this cache. Negative duration means forever,
+ // 0 is effectively turning this cache off.
+ maxAge time.Duration
nlocker *locker.Locker
}
@@ -49,7 +50,7 @@ type ItemInfo struct {
}
// NewCache creates a new file cache with the given filesystem and max age.
-func NewCache(fs afero.Fs, maxAge int) *Cache {
+func NewCache(fs afero.Fs, maxAge time.Duration) *Cache {
return &Cache{
Fs: fs,
nlocker: locker.NewLocker(),
@@ -227,9 +228,7 @@ func (c *Cache) getOrRemove(id string) hugio.ReadSeekCloser {
return nil
}
- expiry := time.Now().Add(-time.Duration(c.maxAge) * time.Second)
- expired := fi.ModTime().Before(expiry)
- if expired {
+ if time.Now().Sub(fi.ModTime()) > c.maxAge {
c.Fs.Remove(id)
return nil
}