Reduce CPU time when initiating RepositoryCacheKeys (#18267)

* Avoid an unneeded lookups in the Keys dictionary when initiating key cache

* Add further comments and unit tests around updated code.

---------

Co-authored-by: Andy Butland <abutland73@gmail.com>
This commit is contained in:
Henrik
2025-03-26 16:01:53 +01:00
committed by GitHub
parent 37035e6e7f
commit 028da4545e
2 changed files with 49 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Persistence.Repositories;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors;
[TestFixture]
public class RepositoryCacheKeysTests
{
[Test]
public void GetKey_Returns_Expected_Key_For_Type()
{
var key = RepositoryCacheKeys.GetKey<IContent>();
Assert.AreEqual("uRepo_IContent_", key);
}
[Test]
public void GetKey_Returns_Expected_Key_For_Type_And_Id()
{
var key = RepositoryCacheKeys.GetKey<IContent, int>(1000);
Assert.AreEqual("uRepo_IContent_1000", key);
}
}