mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-13 12:17:26 -08:00
fix(cache): only store template cache on primary and transient
This commit is contained in:
parent
27dc979954
commit
b51d1de205
|
@ -17,6 +17,7 @@ func New(flags *platform.Flags) *Engine {
|
|||
env.Init()
|
||||
cfg := LoadConfig(env)
|
||||
env.Var = cfg.Var
|
||||
flags.HasTransient = cfg.TransientPrompt != nil
|
||||
|
||||
ansiWriter := &ansi.Writer{
|
||||
TerminalBackground: shell.ConsoleBackgroundColor(env, cfg.TerminalBackground),
|
||||
|
|
|
@ -67,6 +67,7 @@ type Flags struct {
|
|||
Manual bool
|
||||
Plain bool
|
||||
Primary bool
|
||||
HasTransient bool
|
||||
PromptCount int
|
||||
Cleared bool
|
||||
Version string
|
||||
|
@ -743,12 +744,22 @@ func (env *Shell) Cache() Cache {
|
|||
return env.fileCache
|
||||
}
|
||||
|
||||
func (env *Shell) Close() {
|
||||
defer env.Trace(time.Now())
|
||||
func (env *Shell) saveTemplateCache() {
|
||||
// only store this when in a primary prompt
|
||||
// and when we have a transient prompt in the config
|
||||
canSave := env.CmdFlags.Primary && env.CmdFlags.HasTransient
|
||||
if !canSave {
|
||||
return
|
||||
}
|
||||
templateCache, err := json.Marshal(env.TemplateCache())
|
||||
if err == nil {
|
||||
env.fileCache.Set(TEMPLATECACHE, string(templateCache), 1440)
|
||||
}
|
||||
}
|
||||
|
||||
func (env *Shell) Close() {
|
||||
defer env.Trace(time.Now())
|
||||
env.saveTemplateCache()
|
||||
env.fileCache.Close()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue