Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 9 additions & 3 deletions uSync.Core/Cache/SyncEntityCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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; });
}

Expand Down