From 0f8ed24d1f3c4860d0605bff7aa2818db2204ffc Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 14 Jul 2023 19:39:43 -0400 Subject: [PATCH] Fixed an issue with settings caching using SettingsRepository One may have a settings class that includes a mix of HostSettings, PortalSettings, ModuleSettings and TabModuleSettings. The previous mechanism had different cache keys for PortalId or TabModuleId, but that brough 2 problems: 1. It is possible to have the same number for a portalId and TabModuleId which would invalidate the wrong cache. 2. When reading settings using the GetSettings method overload that takes moduleInfo, it would get stale settings for all PortalSettings if it was saved also using moduleInfo overload. I am on the fence about this PR, but it caches now using always portalId. PROS: It fixed the issue at hand. CONS: It clears the portal settings cache to be clear, not the whole portal settings cache but only the specifiec settings class type being requested. This is maybe a tiny tiny bit of a performance hit, but it's not like saving settings is something that gets hammerd. So I believe the benifits here outweigh the drawbacks. Closes #5739 Possibly a different fix for the workaround in #3756 but I don't have any MVC custom module to test that part... --- .../Library/Entities/Modules/Settings/SettingsRepository.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DNN Platform/Library/Entities/Modules/Settings/SettingsRepository.cs b/DNN Platform/Library/Entities/Modules/Settings/SettingsRepository.cs index 48a8d0daae9..28ace91909c 100644 --- a/DNN Platform/Library/Entities/Modules/Settings/SettingsRepository.cs +++ b/DNN Platform/Library/Entities/Modules/Settings/SettingsRepository.cs @@ -50,7 +50,7 @@ protected virtual string MappingCacheKey /// public T GetSettings(ModuleInfo moduleContext) { - return CBO.GetCachedObject(new CacheItemArgs(this.CacheKey(moduleContext.TabModuleID), 20, CacheItemPriority.AboveNormal, moduleContext), this.Load, false); + return CBO.GetCachedObject(new CacheItemArgs(this.CacheKey(moduleContext.PortalID), 20, CacheItemPriority.AboveNormal, moduleContext), this.Load, false); } /// @@ -164,7 +164,7 @@ private void SaveSettings(int portalId, ModuleInfo moduleContext, T settings) } } }); - DataCache.SetCache(this.CacheKey(moduleContext == null ? portalId : moduleContext.TabModuleID), settings); + DataCache.SetCache(this.CacheKey(portalId), settings); } private T Load(CacheItemArgs args)