From 52c39b8d303b6e33420222a5708010d3f8089088 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Tue, 5 Nov 2024 08:20:21 +0100 Subject: [PATCH] fix(cache): use correct duration strings resolves #5814 resolves #5812 --- src/cache/duration.go | 2 ++ src/cli/toggle.go | 2 +- src/font/fonts.go | 2 +- src/runtime/http/oauth.go | 2 +- src/runtime/terminal.go | 4 ++-- src/upgrade/notice.go | 3 ++- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cache/duration.go b/src/cache/duration.go index f11768d7..cc692a64 100644 --- a/src/cache/duration.go +++ b/src/cache/duration.go @@ -9,6 +9,8 @@ type Duration string const ( INFINITE = Duration("infinite") ONEWEEK = Duration("168h") + ONEDAY = Duration("24h") + TWOYEARS = Duration("17520h") ) func (d Duration) Seconds() int { diff --git a/src/cli/toggle.go b/src/cli/toggle.go index a59fc5d3..bc7c963a 100644 --- a/src/cli/toggle.go +++ b/src/cli/toggle.go @@ -50,7 +50,7 @@ var toggleCmd = &cobra.Command{ newToggles = append(newToggles, segment) } - env.Session().Set(cache.TOGGLECACHE, strings.Join(newToggles, ","), "1day") + env.Session().Set(cache.TOGGLECACHE, strings.Join(newToggles, ","), cache.ONEDAY) }, } diff --git a/src/font/fonts.go b/src/font/fonts.go index 996581e8..12c53bdf 100644 --- a/src/font/fonts.go +++ b/src/font/fonts.go @@ -78,7 +78,7 @@ func setCachedFontData(assets []*Asset) { return } - environment.Cache().Set(cache.FONTLISTCACHE, string(data), "1day") + environment.Cache().Set(cache.FONTLISTCACHE, string(data), cache.ONEDAY) } func CascadiaCode() ([]*Asset, error) { diff --git a/src/runtime/http/oauth.go b/src/runtime/http/oauth.go index 6c387d2b..939e0842 100644 --- a/src/runtime/http/oauth.go +++ b/src/runtime/http/oauth.go @@ -91,7 +91,7 @@ func (o *OAuthRequest) refreshToken(refreshToken string) (string, error) { // add tokens to cache o.Env.Cache().Set(o.AccessTokenKey, tokens.AccessToken, cache.ToDuration(tokens.ExpiresIn)) - o.Env.Cache().Set(o.RefreshTokenKey, tokens.RefreshToken, "2years") + o.Env.Cache().Set(o.RefreshTokenKey, tokens.RefreshToken, cache.TWOYEARS) return tokens.AccessToken, nil } diff --git a/src/runtime/terminal.go b/src/runtime/terminal.go index 2a18fc41..fb190061 100644 --- a/src/runtime/terminal.go +++ b/src/runtime/terminal.go @@ -591,7 +591,7 @@ func (term *Terminal) saveTemplateCache() { templateCache, err := json.Marshal(tmplCache) if err == nil { - term.sessionCache.Set(cache.TEMPLATECACHE, string(templateCache), "1day") + term.sessionCache.Set(cache.TEMPLATECACHE, string(templateCache), cache.ONEDAY) } } @@ -757,7 +757,7 @@ func (term *Terminal) setPromptCount() { // Only update the count if we're generating a primary prompt. if term.CmdFlags.Primary { count++ - term.Session().Set(cache.PROMPTCOUNTCACHE, strconv.Itoa(count), "1day") + term.Session().Set(cache.PROMPTCOUNTCACHE, strconv.Itoa(count), cache.ONEDAY) } term.CmdFlags.PromptCount = count diff --git a/src/upgrade/notice.go b/src/upgrade/notice.go index ce17b03b..018d0df6 100644 --- a/src/upgrade/notice.go +++ b/src/upgrade/notice.go @@ -6,6 +6,7 @@ import ( "time" "github.com/jandedobbeleer/oh-my-posh/src/build" + "github.com/jandedobbeleer/oh-my-posh/src/cache" "github.com/jandedobbeleer/oh-my-posh/src/runtime" "github.com/jandedobbeleer/oh-my-posh/src/runtime/http" ) @@ -83,7 +84,7 @@ func Notice(env runtime.Environment, force bool) (string, bool) { return "", false } - env.Cache().Set(CACHEKEY, latest, "1week") + env.Cache().Set(CACHEKEY, latest, cache.ONEWEEK) version := fmt.Sprintf("v%s", build.Version) if latest == version {