From b51d1de20530699fbee98369e120eff7b2dbe7e8 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Mon, 8 May 2023 13:15:59 +0200 Subject: [PATCH] fix(cache): only store template cache on primary and transient --- src/engine/new.go | 1 + src/platform/shell.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/engine/new.go b/src/engine/new.go index fea6ac6c..13732a43 100644 --- a/src/engine/new.go +++ b/src/engine/new.go @@ -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), diff --git a/src/platform/shell.go b/src/platform/shell.go index 0301e2d8..605409c2 100644 --- a/src/platform/shell.go +++ b/src/platform/shell.go @@ -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() }