Skip to content

Commit

Permalink
cache
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Jul 20, 2023
1 parent 3cb6c54 commit dda7add
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions d2cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,12 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
}

func LayoutResolver(ctx context.Context, ms *xmain.State, plugins []d2plugin.Plugin) func(engine string) (d2graph.LayoutGraph, error) {
cached := make(map[string]d2graph.LayoutGraph)
return func(engine string) (d2graph.LayoutGraph, error) {
if c, ok := cached[engine]; ok {
return c, nil
}

plugin, err := d2plugin.FindPlugin(ctx, plugins, engine)
if err != nil {
if errors.Is(err, exec.ErrNotFound) {
Expand All @@ -355,6 +360,7 @@ func LayoutResolver(ctx context.Context, ms *xmain.State, plugins []d2plugin.Plu
return nil, err
}

cached[engine] = plugin.Layout
return plugin.Layout, nil
}
}
Expand Down

0 comments on commit dda7add

Please sign in to comment.