aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/cache/v1.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2021-02-27 23:39:51 +0100
committerRené 'Necoro' Neumann <necoro@necoro.eu>2021-02-27 23:40:00 +0100
commitc407994dd3aeb2c5a8e5f3fa070e7436fe308fc9 (patch)
tree79adc06c0a5865badd83bfd0f515c21791d81d2b /internal/feed/cache/v1.go
parent21210173c4d04676436b8e48dfbe4043299797cb (diff)
downloadfeed2imap-go-c407994dd3aeb2c5a8e5f3fa070e7436fe308fc9.tar.gz
feed2imap-go-c407994dd3aeb2c5a8e5f3fa070e7436fe308fc9.tar.bz2
feed2imap-go-c407994dd3aeb2c5a8e5f3fa070e7436fe308fc9.zip
Remove obsolete feeds from cache after 180 days
Diffstat (limited to 'internal/feed/cache/v1.go')
-rw-r--r--internal/feed/cache/v1.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/internal/feed/cache/v1.go b/internal/feed/cache/v1.go
index 0363303..5675db5 100644
--- a/internal/feed/cache/v1.go
+++ b/internal/feed/cache/v1.go
@@ -23,6 +23,7 @@ const (
v1Version Version = 1
startFeedId uint64 = 1
maxCacheSize = 1000
+ maxCacheDays = 180
)
type feedId uint64
@@ -376,6 +377,21 @@ func filterItems(items []cachedItem) []cachedItem {
return copiedItems
}
+func (cache *v1Cache) cleanup(knownDescriptors map[feed.Descriptor]bool) {
+ for descr, id := range cache.Ids {
+ if knownDescriptors[descr] {
+ // do not delete stuff still known to us
+ continue
+ }
+
+ cf := cache.Feeds[id]
+ if cf.LastCheck.IsZero() || util.Days(time.Since(cf.LastCheck)) > maxCacheDays {
+ delete(cache.Feeds, id)
+ delete(cache.Ids, descr)
+ }
+ }
+}
+
func (cache *v1Cache) load(reader io.Reader) error {
decoder := gob.NewDecoder(reader)
return decoder.Decode(cache)