Skip to content

Commit

Permalink
fix(cache): use correct duration strings
Browse files Browse the repository at this point in the history
resolves #5814
resolves #5812
  • Loading branch information
JanDeDobbeleer committed Nov 5, 2024
1 parent 2a3b26f commit 52c39b8
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/cache/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/toggle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down
2 changes: 1 addition & 1 deletion src/font/fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/http/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/upgrade/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 52c39b8

Please sign in to comment.