Skip to content

Commit

Permalink
Fixed an issue with settings caching using SettingsRepository
Browse files Browse the repository at this point in the history
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 dnnsoftware#5739

Possibly a different fix for the workaround in dnnsoftware#3756 but I don't have any MVC custom module to test that part...
  • Loading branch information
valadas committed Jul 14, 2023
1 parent 71c696f commit 0f8ed24
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected virtual string MappingCacheKey
/// <inheritdoc/>
public T GetSettings(ModuleInfo moduleContext)
{
return CBO.GetCachedObject<T>(new CacheItemArgs(this.CacheKey(moduleContext.TabModuleID), 20, CacheItemPriority.AboveNormal, moduleContext), this.Load, false);
return CBO.GetCachedObject<T>(new CacheItemArgs(this.CacheKey(moduleContext.PortalID), 20, CacheItemPriority.AboveNormal, moduleContext), this.Load, false);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0f8ed24

Please sign in to comment.