From 1ca5872a5a67bf8aa44f04650d87b42011cb7463 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 18 Apr 2022 12:10:15 -0700 Subject: [PATCH] Define component types which can be cached --- internal/plugin/plugin.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/internal/plugin/plugin.go b/internal/plugin/plugin.go index c38e2f2e9..0b0de865f 100644 --- a/internal/plugin/plugin.go +++ b/internal/plugin/plugin.go @@ -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 +}