Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed persistance of "Replace Tokens" setting in module cache #5846

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ protected virtual string MappingCacheKey
/// <inheritdoc/>
public T GetSettings(ModuleInfo moduleContext)
{
return CBO.GetCachedObject<T>(new CacheItemArgs(this.CacheKey(moduleContext.PortalID), 20, CacheItemPriority.AboveNormal, moduleContext), this.Load, false);
return CBO.GetCachedObject<T>(new CacheItemArgs(this.CacheKey(moduleContext.PortalID, moduleContext.TabModuleID), 20, CacheItemPriority.AboveNormal, moduleContext), this.Load, false);
}

/// <inheritdoc/>
public T GetSettings(int portalId)
{
return CBO.GetCachedObject<T>(new CacheItemArgs(this.CacheKey(portalId), 20, CacheItemPriority.AboveNormal, null, portalId), this.Load, false);
return CBO.GetCachedObject<T>(new CacheItemArgs(this.CacheKey(portalId, -1), 20, CacheItemPriority.AboveNormal, null, portalId), this.Load, false);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -164,7 +164,13 @@ private void SaveSettings(int portalId, ModuleInfo moduleContext, T settings)
}
}
});
DataCache.SetCache(this.CacheKey(portalId), settings);

DataCache.ClearCache(this.CacheKeyPortalPrefix(portalId));
DataCache.SetCache(this.CacheKey(portalId, -1), settings);
GerardSmit marked this conversation as resolved.
Show resolved Hide resolved
if (moduleContext is not null)
{
DataCache.SetCache(this.CacheKey(portalId, moduleContext.TabModuleID), settings);
}
}

private T Load(CacheItemArgs args)
Expand Down Expand Up @@ -220,7 +226,17 @@ private T Load(CacheItemArgs args)
return settings;
}

private string CacheKey(int id) => $"Settings{this.MappingCacheKey}_{id}";
/// <summary>Gets the cache key for the given portal and tab module.</summary>
/// <param name="portalId">The portal ID.</param>
/// <param name="tabModuleId">The tab module ID.</param>
/// <remarks>When <paramref name="tabModuleId"/> is -1, the cache key is for portal settings instead.</remarks>
/// <returns>The cache key.</returns>
private string CacheKey(int portalId, int tabModuleId) => $"{this.CacheKeyPortalPrefix(portalId)}{tabModuleId}";

/// <summary>Gets the prefix of the cache key for the given portal.</summary>
/// <param name="portalId">The portal ID.</param>
/// <returns>The cache key prefix.</returns>
private string CacheKeyPortalPrefix(int portalId) => $"Settings{this.MappingCacheKey}_{portalId}_";

/// <summary>Deserializes the property.</summary>
/// <param name="settings">The settings.</param>
Expand Down