Skip to content

Commit

Permalink
+ (CMS) Fix issue where WebsiteLavaTemplateCache returns an error and…
Browse files Browse the repository at this point in the history
… cannot be cleared. (Fixes SparkDevNetwork#5250)

+ (CMS) Fix issue where WebsiteLavaTemplateCache returns an error and cannot be cleared. (Fixes SparkDevNetwork#5250)
  • Loading branch information
courtneycooksey committed Jan 23, 2023
1 parent 073a612 commit 544c4b9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
26 changes: 14 additions & 12 deletions Rock/Web/Cache/RockCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static List<CacheKeyReference> ObjectCacheKeyReferences
{
_objectCacheKeyReferences = value;
}
}
}
private static List<CacheKeyReference> _objectCacheKeyReferences = new List<CacheKeyReference>();

/// <summary>
Expand All @@ -184,8 +184,10 @@ public static List<CacheKeyReference> StringCacheKeyReferences
}
return _stringCacheKeyReferences;
}
set {
_stringCacheKeyReferences = value; }
set
{
_stringCacheKeyReferences = value;
}
}
private static List<CacheKeyReference> _stringCacheKeyReferences = new List<CacheKeyReference>();

Expand Down Expand Up @@ -276,8 +278,8 @@ public static object GetOrAddExisting( string key, string region, Func<object> i
Expiration = expiration,
AllowCacheBypass = false
};
return GetOrAddExisting(args);

return GetOrAddExisting( args );
}

/// <summary>
Expand Down Expand Up @@ -426,7 +428,7 @@ public static void AddOrUpdate( string key, string region, object obj, TimeSpan
}

var value = RockCacheManager<List<string>>.Instance.Get( cacheTag, CACHE_TAG_REGION_NAME ) ?? new List<string>();
if ( !value.Contains(key) )
if ( !value.Contains( key ) )
{
value.Add( key );
RockCacheManager<List<string>>.Instance.AddOrUpdate( cacheTag, CACHE_TAG_REGION_NAME, value );
Expand Down Expand Up @@ -539,7 +541,7 @@ public static string ClearCachedItemsForType( string cacheTypeName )

if ( cacheTypeName.Contains( "Cache" ) )
{
return ClearCachedItemsForType( Type.GetType( $"Rock.Web.Cache.{cacheTypeName},Rock" ) );
return ClearCachedItemsForType( Type.GetType( cacheTypeName ) );
}

return ClearCachedItemsForSystemType( cacheTypeName );
Expand Down Expand Up @@ -642,7 +644,7 @@ public static List<CacheItemStatistics> GetAllStatistics()
/// <returns></returns>
public static CacheItemStatistics GetStatisticsForType( Type cacheType )
{
var cacheStats = new CacheItemStatistics( string.Empty );
var cacheStats = new CacheItemStatistics( string.Empty, string.Empty );
if ( _allManagers == null )
{
return cacheStats;
Expand All @@ -669,7 +671,7 @@ public static CacheItemStatistics GetStatisticsForType( Type cacheType )
/// <returns></returns>
public static CacheItemStatistics GetStatForSystemType( string cacheTypeName )
{
var cacheStats = new CacheItemStatistics( string.Empty );
var cacheStats = new CacheItemStatistics( string.Empty, string.Empty );
if ( _allManagers == null )
{
return cacheStats;
Expand Down Expand Up @@ -700,7 +702,7 @@ public static CacheItemStatistics GetStatisticsForType( string cacheTypeName )
{
if ( cacheTypeName.Contains( "Cache" ) )
{
return GetStatisticsForType( Type.GetType( $"Rock.Web.Cache.{cacheTypeName},Rock" ) );
return GetStatisticsForType( Type.GetType( cacheTypeName ) );
}

return GetStatForSystemType( cacheTypeName );
Expand All @@ -726,11 +728,11 @@ public static bool IsEndPointAvailable( string socket, string password )
{
configurationOptions.Password = password;
}

var redisConnection = StackExchange.Redis.ConnectionMultiplexer.Connect( configurationOptions );
return redisConnection.IsConnected;
}
catch(Exception)
catch ( Exception )
{
return false;
}
Expand Down
16 changes: 14 additions & 2 deletions Rock/Web/Cache/RockCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,14 @@ public CacheItemStatistics GetStatistics()
var type = typeof( T );

string name = type.Name;
string fullname = type.FullName;
if ( type.IsGenericType && type.GenericTypeArguments[0] != null )
{
name = type.GenericTypeArguments[0].ToString();
fullname = type.GenericTypeArguments[0].ToString();
}

var cacheStatistics = new CacheItemStatistics( name );
var cacheStatistics = new CacheItemStatistics( name, fullname );

foreach ( var handle in CacheManager.CacheHandles )
{
Expand Down Expand Up @@ -440,6 +442,14 @@ public class CacheItemStatistics
/// </value>
public string Name { get; set; }

/// <summary>
/// Gets or sets the full name.
/// </summary>
/// <value>
/// The name.
/// </value>
public string FullName { get; set; }

/// <summary>
/// Gets or sets the handle stats.
/// </summary>
Expand All @@ -452,9 +462,11 @@ public class CacheItemStatistics
/// Initializes a new instance of the <see cref="CacheItemStatistics"/> class.
/// </summary>
/// <param name="name">The name.</param>
public CacheItemStatistics( string name )
/// <param name="fullname">The full name.</param>
public CacheItemStatistics( string name, string fullname )
{
Name = name;
FullName = fullname;
}
}

Expand Down
10 changes: 5 additions & 5 deletions RockWeb/Blocks/Cms/CacheManager.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ protected void PopulateDdlCacheTypes()
var cacheStats = RockCache.GetAllStatistics();
foreach ( CacheItemStatistics cacheItemStat in cacheStats.OrderBy( s => s.Name ) )
{
ddlCacheTypes.Items.Add( new ListItem( cacheItemStat.Name, cacheItemStat.Name ) );
ddlCacheTypes.Items.Add( new ListItem( cacheItemStat.Name, cacheItemStat.FullName ) );
}
}

Expand Down Expand Up @@ -544,7 +544,7 @@ protected void ddlCacheTypes_SelectedIndexChanged( object sender, EventArgs e )
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void rcbEnableStatistics_CheckedChanged(object sender, EventArgs e)
protected void rcbEnableStatistics_CheckedChanged( object sender, EventArgs e )
{
// Save updated value.
SystemSettings.SetValueToWebConfig( Rock.SystemKey.SystemSetting.CACHE_MANAGER_ENABLE_STATISTICS, rcbEnableStatistics.Checked.ToString() );
Expand Down Expand Up @@ -582,7 +582,7 @@ protected void dlgAddTag_SaveClick( object sender, EventArgs e )
private bool IsValid()
{
// Don't need to check for an edited tag as only the description is being changed.
if(hfTagId.Value.IsNotNullOrWhiteSpace() )
if ( hfTagId.Value.IsNotNullOrWhiteSpace() )
{
return true;
}
Expand Down Expand Up @@ -615,7 +615,7 @@ private bool IsValid()
/// </summary>
private void SaveTag()
{
if (hfTagId.Value == string.Empty)
if ( hfTagId.Value == string.Empty )
{
SaveNewTag();
}
Expand Down Expand Up @@ -657,7 +657,7 @@ private void SaveNewTag()
/// Updates and existing tag.
/// </summary>
/// <param name="cacheTagId">The Id of the tag.</param>
private void UpdateExistingTag(int cacheTagId )
private void UpdateExistingTag( int cacheTagId )
{
using ( var rockContext = new RockContext() )
{
Expand Down

0 comments on commit 544c4b9

Please sign in to comment.