Skip to content

Commit

Permalink
Fixed module cache (#5846)
Browse files Browse the repository at this point in the history
Co-authored-by: Brian Dukes <[email protected]>
  • Loading branch information
GerardSmit and bdukes authored Oct 17, 2023
1 parent 39c25b7 commit e0edebb
Showing 1 changed file with 16 additions and 4 deletions.
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,9 @@ 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, moduleContext?.TabModuleID ?? -1), settings);
}

private T Load(CacheItemArgs args)
Expand Down Expand Up @@ -220,7 +222,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

0 comments on commit e0edebb

Please sign in to comment.