diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-27 22:26:34 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-27 22:26:34 +0100 |
commit | f4ea0b4fca4fae270d785b84e9b105081826754f (patch) | |
tree | 79deeecf52872cfeaad45ba23d975e52f64c718b /internal/feed/cache/cache.go | |
parent | ae96e1bd2516ff2c70ad9dc010da84b7a03b9a35 (diff) | |
download | feed2imap-go-f4ea0b4fca4fae270d785b84e9b105081826754f.tar.gz feed2imap-go-f4ea0b4fca4fae270d785b84e9b105081826754f.tar.bz2 feed2imap-go-f4ea0b4fca4fae270d785b84e9b105081826754f.zip |
New cache format using gzip compression
Diffstat (limited to 'internal/feed/cache/cache.go')
-rw-r--r-- | internal/feed/cache/cache.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/internal/feed/cache/cache.go b/internal/feed/cache/cache.go index 9613f06..1ea8eaf 100644 --- a/internal/feed/cache/cache.go +++ b/internal/feed/cache/cache.go @@ -18,7 +18,7 @@ import ( type Version byte const ( - currentVersion Version = v1Version + currentVersion Version = v2Version ) type Impl interface { @@ -56,6 +56,8 @@ func forVersion(version Version) (Impl, error) { switch version { case v1Version: return newV1Cache(), nil + case v2Version: + return newV2Cache(), nil default: return nil, fmt.Errorf("unknown cache version '%d'", version) } @@ -169,11 +171,15 @@ func Load(fileName string) (Cache, error) { return Cache{}, fmt.Errorf("decoding for version '%d' from '%s': %w", version, fileName, err) } - if cache, err = cache.transformTo(currentVersion); err != nil { - return Cache{}, fmt.Errorf("cannot transform from version %d to %d: %w", version, currentVersion, err) - } + if currentVersion != cache.Version() { + if cache, err = cache.transformTo(currentVersion); err != nil { + return Cache{}, fmt.Errorf("cannot transform from version %d to %d: %w", version, currentVersion, err) + } - log.Printf("Loaded cache (version %d), transformed to version %d.", version, currentVersion) + log.Printf("Loaded cache (version %d), transformed to version %d.", version, currentVersion) + } else { + log.Printf("Loaded cache (version %d)", version) + } return Cache{cache, lock, true}, nil } |