Cache the machine instance of the target

This commit is contained in:
Chris Roberts 2022-04-27 15:56:49 -07:00
parent 4e6c24b631
commit bd849581f6

View File

@ -331,14 +331,27 @@ func (t *Target) seed(fn func(*core.Seeds)) {
// Specializes target into a machine
func (t *Target) Machine() core.Machine {
cm := t.cache.Get("machine")
if cm != nil {
return cm.(core.Machine)
}
targetMachine := &vagrant_server.Target_Machine{}
ptypes.UnmarshalAny(t.target.Record, targetMachine)
return &Machine{
m := &Machine{
Target: t,
logger: t.logger,
machine: targetMachine,
cache: cacher.New(),
}
t.Closer(func() error {
return m.Save()
})
t.cache.Register("machine", m)
return m
}
// Calls the function provided and converts the