A cache key as a pair of a root page's content reference and a singleton page's type.
 /// <summary>
 /// Gets or adds a singleton page content reference to the cache when not empty.
 /// </summary>
 /// <param name="key">Cache key as a pair of the root page content reference and singleton page type.</param>
 /// <param name="valueFactory">Factory function to get singleton page content reference.</param>
 /// <returns>A singleton page's content reference.</returns>
 public ContentReference GetOrAdd(CacheKey key, Func<ContentReference> valueFactory)
 {
     ContentReference value;
     if (Cache.TryGetValue(key, out value))
     {
         return value;
     }
     value = valueFactory();
     return value == ContentReference.EmptyReference ? value : Cache.GetOrAdd(key, value);
 }
예제 #2
0
        public void it_adds_found_page_data_to_cache_on_first_call()
        {
            var fakeRoot = FakePage.Create("Root");
            var fakeStart = FakePage.Create("Start")
                                    .ChildOf(fakeRoot);
            var fakeExpected = FakePage.Create<TestPage>("Test page")
                                        .ChildOf(fakeStart);
            _fake.AddToRepository(fakeRoot);
            var expected = fakeExpected.Page.ContentLink;

            fakeStart.Page.PageLink.GetSingletonPage<TestPage>();

            var key = new CacheKey(typeof(TestPage), fakeStart.Page.PageLink);
            var actual = _fakeCache.InternalCache[key];
            Assert.Equal(expected, actual);
        }
예제 #3
0
 /// <summary>
 /// Determines whether two specified CacheKey objects have the same value.
 /// </summary>
 /// <param name="other">The CacheKey to compare to this instance.</param>
 /// <returns>true if the specified CacheKey is equal to the current CacheKey; otherwise, false.</returns>
 protected bool Equals(CacheKey other)
 {
     return Type == other.Type && Equals(ParentLink, other.ParentLink);
 }
예제 #4
0
        public void it_does_not_add_empty_content_link_to_the_cache()
        {
            var fakeRoot = FakePage.Create("Root");
            var fakeStart = FakePage.Create("Start")
                                    .ChildOf(fakeRoot);
            _fake.AddToRepository(fakeRoot);

            fakeStart.Page.PageLink.GetSingletonPage<TestPage>();

            var key = new CacheKey(typeof(TestPage), fakeStart.Page.PageLink);
            var actual = _fakeCache.InternalCache.ContainsKey(key);
            Assert.False(actual);
        }