当前位置: 首页>>代码示例>>C#>>正文


C# Cache.GetElementById方法代码示例

本文整理汇总了C#中Cache.GetElementById方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.GetElementById方法的具体用法?C# Cache.GetElementById怎么用?C# Cache.GetElementById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cache的用法示例。


在下文中一共展示了Cache.GetElementById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TypesOfStorage_CorrectGettingElementsFromCacheAndDataBase

        public void TypesOfStorage_CorrectGettingElementsFromCacheAndDataBase()
        {
            var dataBase = GenerateDataBaseOfRandomStringElements(3);
            var cache = new Cache<string>(2, dataBase);
            var listOfId = dataBase.GetListOfId();
            var elements = new List<Element<string>>();

            foreach (var identifier in listOfId)
                elements.Add(cache.GetElementById(identifier));

            var expectedTypeStorageOfFirstElement = TypesOfStorage.DataBase;
            var expectedTypeStorageOfSecondElement = TypesOfStorage.DataBase;
            var expectedTypeStorageOfThirdElement = TypesOfStorage.DataBase;

            var actualTypeStorageOfFirstElement = elements[0].TypeOfStorage;
            var actualTypeStorageOfSecondElement = elements[1].TypeOfStorage;
            var actualTypeStorageOfThirdElement = elements[2].TypeOfStorage;

            Assert.AreEqual(expectedTypeStorageOfFirstElement, actualTypeStorageOfFirstElement, "First Element From Data Base");
            Assert.AreEqual(expectedTypeStorageOfSecondElement, actualTypeStorageOfSecondElement, "Second Element From Data Base");
            Assert.AreEqual(expectedTypeStorageOfThirdElement, actualTypeStorageOfThirdElement, "Third Element From Data Base");

            RepeatedRequestToLastTwoElements(cache, listOfId);

            expectedTypeStorageOfFirstElement = TypesOfStorage.DataBase;
            expectedTypeStorageOfSecondElement = TypesOfStorage.Cache;
            expectedTypeStorageOfThirdElement = TypesOfStorage.Cache;

            actualTypeStorageOfFirstElement = elements[0].TypeOfStorage;
            actualTypeStorageOfSecondElement = elements[1].TypeOfStorage;
            actualTypeStorageOfThirdElement = elements[2].TypeOfStorage;

            Assert.AreEqual(expectedTypeStorageOfFirstElement, actualTypeStorageOfFirstElement, "First Element From Data Base");
            Assert.AreEqual(expectedTypeStorageOfSecondElement, actualTypeStorageOfSecondElement, "Second Element From Cache");
            Assert.AreEqual(expectedTypeStorageOfThirdElement, actualTypeStorageOfThirdElement, "Third Element From Cache");
        }
开发者ID:Confirmit,项目名称:Students,代码行数:36,代码来源:CacheLibrary.UnitTests.cs

示例2: RepeatedRequestToLastTwoElements

 private static void RepeatedRequestToLastTwoElements(Cache<string> cache, List<string> listOfId)
 {
     //Why do we need this variable?
     var someInformationAboutSecondElement = cache.GetElementById(listOfId[1]);
     var someInformationAboutThirdElement = cache.GetElementById(listOfId[2]);
 }
开发者ID:Confirmit,项目名称:Students,代码行数:6,代码来源:CacheLibrary.UnitTests.cs


注:本文中的Cache.GetElementById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。