Define component types which can be cached

This commit is contained in:
Chris Roberts 2022-04-18 12:10:15 -07:00 committed by Paul Hinze
parent 0c5d02ca53
commit 1ca5872a5a
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0

View File

@ -33,6 +33,14 @@ var (
"myplugin": myplugin.CommandOptions,
"otherplugin": otherplugin.CommandOptions,
}
CacheableComponents = []component.Type{
component.CommandType,
component.ConfigType,
component.HostType,
component.MapperType,
component.PluginInfoType,
component.PushType,
}
)
type Plugin struct {
@ -186,8 +194,10 @@ func (p *Plugin) InstanceOf(
return
}
// Store the instance for later usage
p.components[c] = i
if p.isCacheable(c) {
// Store the instance for later usage
p.components[c] = i
}
return
}
@ -258,3 +268,13 @@ func (p *Plugin) loadParent(i *Instance) error {
return nil
}
// Check if component type can be cached
func (p *Plugin) isCacheable(t component.Type) bool {
for _, v := range CacheableComponents {
if t == v {
return true
}
}
return false
}