Define component types which can be cached
This commit is contained in:
parent
0c5d02ca53
commit
1ca5872a5a
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user