本文整理汇总了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");
}
示例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]);
}