diff --git a/uSync.Core/Cache/SyncEntityCache.cs b/uSync.Core/Cache/SyncEntityCache.cs index c712560fe..2bcbcbb7e 100644 --- a/uSync.Core/Cache/SyncEntityCache.cs +++ b/uSync.Core/Cache/SyncEntityCache.cs @@ -47,7 +47,11 @@ public CachedName GetName(int id) public void AddName(int id, Guid guid, string name) { - nameCache.ClearByKey(id.ToString()); + // was ClearByKey(id.ToString()) - a full LINQ scan of every entry in nameCache + // looking for a prefix match, on every single call. id.ToString() is an exact + // key here (no other key is ever a variant/suffix of it in this cache), so a + // direct single-key removal is correct and avoids the O(n) scan entirely. + nameCache.Clear(id.ToString()); nameCache.GetCacheItem(id.ToString(), () => { return new CachedName(guid, name); @@ -103,7 +107,8 @@ public IEntitySlim GetEntity(Guid id) } else { - keyCache.ClearByKey(id.ToString()); + // was ClearByKey (O(n) scan) - id.ToString() is an exact key here too. + keyCache.Clear(id.ToString()); return null; } } @@ -134,7 +139,8 @@ public IEntitySlim GetEntity(Guid id, UmbracoObjectTypes objectType) } else { - keyCache.ClearByKey(id.ToString()); + // was ClearByKey (O(n) scan) - id.ToString() is an exact key here too. + keyCache.Clear(id.ToString()); return null; } } diff --git a/uSync.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs b/uSync.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs index 509e113a8..7b2dcf793 100644 --- a/uSync.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs +++ b/uSync.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs @@ -659,7 +659,9 @@ private void EnsureAliasCache() protected void ClearAliases() { aliasCache = null; - _appCache.ClearByKey($"usync_{this.Id}"); + // was ClearByKey (O(n) scan of the whole shared RuntimeCache) - the key here is + // exact (this.Id is a single content type), so a direct removal is correct. + _appCache.Clear($"usync_{this.Id}"); } protected void RemoveAlias(string alias) @@ -675,7 +677,9 @@ protected void RemoveAlias(string alias) private void RefreshAliasCache() { - _appCache.ClearByKey($"usync_{this.Id}"); + // was ClearByKey (O(n) scan of the whole shared RuntimeCache) - the key here is + // exact (this.Id is a single content type), so a direct removal is correct. + _appCache.Clear($"usync_{this.Id}"); _appCache.GetCacheItem($"usync_{this.Id}", () => { return aliasCache; }); }