aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/cache/state.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/state.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/state.go')
-rw-r--r--internal/feed/cache/state.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/internal/feed/cache/state.go b/internal/feed/cache/state.go
index 2df0c74..ce6723a 100644
--- a/internal/feed/cache/state.go
+++ b/internal/feed/cache/state.go
@@ -11,6 +11,7 @@ import (
type State struct {
feeds map[string]*feed.Feed
cachedFeeds map[string]CachedFeed
+ knownFeeds map[feed.Descriptor]bool
cache Cache
cfg *config.Config
}
@@ -55,6 +56,7 @@ func (state *State) LoadCache(fileName string, forceNew bool) error {
for name, feed := range state.feeds {
state.cachedFeeds[name] = cache.cachedFeed(feed)
+ state.knownFeeds[feed.Descriptor()] = true
}
// state.feeds should not be used after loading the cache --> enforce a panic
@@ -64,6 +66,7 @@ func (state *State) LoadCache(fileName string, forceNew bool) error {
}
func (state *State) StoreCache(fileName string) error {
+ state.cache.cleanup(state.knownFeeds)
return state.cache.store(fileName)
}
@@ -115,9 +118,11 @@ func (state *State) Filter() {
}
func NewState(cfg *config.Config) (*State, error) {
+ numFeeds := len(cfg.Feeds)
state := State{
- feeds: map[string]*feed.Feed{},
- cachedFeeds: map[string]CachedFeed{},
+ feeds: make(map[string]*feed.Feed, numFeeds),
+ cachedFeeds: make(map[string]CachedFeed, numFeeds),
+ knownFeeds: make(map[feed.Descriptor]bool, numFeeds),
cache: Cache{}, // loaded later on
cfg: cfg,
}