diff --git a/pkg/api/plugins.go b/pkg/api/plugins.go index 2658391d2cc..93ccc222108 100644 --- a/pkg/api/plugins.go +++ b/pkg/api/plugins.go @@ -263,6 +263,8 @@ func (hs *HTTPServer) UpdatePluginSetting(c *contextmodel.ReqContext) response.R return response.Error(500, "Failed to update plugin setting", err) } + hs.PluginContextProvider.InvalidateSettingsCache(c.Req.Context(), pluginID) + return response.Success("Plugin settings updated") } diff --git a/pkg/plugins/plugincontext/plugincontext.go b/pkg/plugins/plugincontext/plugincontext.go index 9abfd7ab7c6..944d213e9a3 100644 --- a/pkg/plugins/plugincontext/plugincontext.go +++ b/pkg/plugins/plugincontext/plugincontext.go @@ -106,7 +106,7 @@ func (p *Provider) pluginContext(ctx context.Context, pluginID string, user *use } func (p *Provider) getCachedPluginSettings(ctx context.Context, pluginID string, user *user.SignedInUser) (*pluginsettings.DTO, error) { - cacheKey := pluginSettingsCachePrefix + pluginID + cacheKey := getCacheKey(pluginID) if cached, found := p.cacheService.Get(cacheKey); found { ps := cached.(*pluginsettings.DTO) @@ -127,8 +127,16 @@ func (p *Provider) getCachedPluginSettings(ctx context.Context, pluginID string, return ps, nil } +func (p *Provider) InvalidateSettingsCache(_ context.Context, pluginID string) { + p.cacheService.Delete(getCacheKey(pluginID)) +} + func (p *Provider) decryptSecureJsonDataFn(ctx context.Context) func(ds *datasources.DataSource) (map[string]string, error) { return func(ds *datasources.DataSource) (map[string]string, error) { return p.dataSourceService.DecryptedValues(ctx, ds) } } + +func getCacheKey(pluginID string) string { + return pluginSettingsCachePrefix + pluginID +}