本文整理汇总了C#中CacheItem.SetLastAccessedTime方法的典型用法代码示例。如果您正苦于以下问题:C# CacheItem.SetLastAccessedTime方法的具体用法?C# CacheItem.SetLastAccessedTime怎么用?C# CacheItem.SetLastAccessedTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CacheItem
的用法示例。
在下文中一共展示了CacheItem.SetLastAccessedTime方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WillSortByPriorityWithSameDate
public void WillSortByPriorityWithSameDate()
{
CacheItem firstItem = new CacheItem("key", "value", CacheItemPriority.High, null);
CacheItem secondItem = new CacheItem("key2", "value2", CacheItemPriority.NotRemovable, null);
CacheItem thirdItem = new CacheItem("key3", "value3", CacheItemPriority.Low, null);
CacheItem fourthItem = new CacheItem("key4", "value4", CacheItemPriority.Normal, null);
DateTime currentTime = DateTime.Now;
firstItem.SetLastAccessedTime(currentTime);
secondItem.SetLastAccessedTime(currentTime);
thirdItem.SetLastAccessedTime(currentTime);
fourthItem.SetLastAccessedTime(currentTime);
AddCacheItem("key", firstItem);
AddCacheItem("key2", secondItem);
AddCacheItem("key3", thirdItem);
AddCacheItem("key4", fourthItem);
SortedList itemsToBeScavenged = new SortedList(inMemoryCache, new PriorityDateComparer(inMemoryCache));
Assert.AreEqual("key3", GetCacheKey(itemsToBeScavenged, 0));
Assert.AreEqual("key4", GetCacheKey(itemsToBeScavenged, 1));
Assert.AreEqual("key", GetCacheKey(itemsToBeScavenged, 2));
Assert.AreEqual("key2", GetCacheKey(itemsToBeScavenged, 3));
}
示例2: CanInitializeWithLastUpdatedTimeFromCacheItem
public void CanInitializeWithLastUpdatedTimeFromCacheItem()
{
CacheItem item = new CacheItem("key", "value", CacheItemPriority.Normal, null);
DateTime timestampToSave = DateTime.Now + TimeSpan.FromDays(1.0);
item.SetLastAccessedTime(timestampToSave);
DateTime initialTimeStamp = DateTime.Now - TimeSpan.FromSeconds(5.0);
TimeSpan expirationWindow = TimeSpan.FromSeconds(5.0);
SlidingTime slidingTime = new SlidingTime(expirationWindow, initialTimeStamp);
slidingTime.Initialize(item);
Assert.AreEqual(timestampToSave, slidingTime.TimeLastUsed);
}
示例3: ReadMinimalCacheItemFromIsolatedStorageEncrypted
void ReadMinimalCacheItemFromIsolatedStorageEncrypted(bool encrypted)
{
DateTime historicalTimestamp = DateTime.Now - TimeSpan.FromHours(1.0);
CacheItem itemToStore = new CacheItem("key1", "value1", CacheItemPriority.Normal, null);
itemToStore.SetLastAccessedTime(historicalTimestamp);
CacheItem readItem = DoCacheItemRoundTripToStorage(itemToStore, encrypted);
Assert.AreEqual("key1", readItem.Key);
Assert.AreEqual("value1", readItem.Value);
Assert.AreEqual(CacheItemPriority.Normal, readItem.ScavengingPriority);
Assert.IsNull(readItem.RefreshAction);
ICacheItemExpiration[] expirations = readItem.GetExpirations();
Assert.AreEqual(0, expirations.Length);
Assert.AreEqual(historicalTimestamp, readItem.LastAccessedTime);
}
示例4: BigSortingTest
public void BigSortingTest()
{
CacheItem firstItem = new CacheItem("key", "value", CacheItemPriority.High, null);
CacheItem secondItem = new CacheItem("key2", "value2", CacheItemPriority.NotRemovable, null);
CacheItem thirdItem = new CacheItem("key3", "value3", CacheItemPriority.Low, null);
CacheItem fourthItem = new CacheItem("key4", "value4", CacheItemPriority.Normal, null);
CacheItem fifthItem = new CacheItem("key5", "value", CacheItemPriority.High, null);
CacheItem sixthItem = new CacheItem("key6", "value2", CacheItemPriority.NotRemovable, null);
CacheItem seventhItem = new CacheItem("key7", "value3", CacheItemPriority.Low, null);
CacheItem eighthItem = new CacheItem("key8", "value4", CacheItemPriority.Normal, null);
DateTime currentTime = DateTime.Now;
DateTime oneHourInFuture = DateTime.Now + TimeSpan.FromHours(1.0);
firstItem.SetLastAccessedTime(oneHourInFuture);
secondItem.SetLastAccessedTime(oneHourInFuture);
thirdItem.SetLastAccessedTime(oneHourInFuture);
fourthItem.SetLastAccessedTime(oneHourInFuture);
fifthItem.SetLastAccessedTime(currentTime);
sixthItem.SetLastAccessedTime(currentTime);
seventhItem.SetLastAccessedTime(currentTime);
eighthItem.SetLastAccessedTime(currentTime);
AddCacheItem("key", firstItem);
AddCacheItem("key2", secondItem);
AddCacheItem("key3", thirdItem);
AddCacheItem("key4", fourthItem);
AddCacheItem("key5", fifthItem);
AddCacheItem("key6", sixthItem);
AddCacheItem("key7", seventhItem);
AddCacheItem("key8", eighthItem);
SortedList itemsToBeScavenged = new SortedList(inMemoryCache, new PriorityDateComparer(inMemoryCache));
Assert.AreEqual("key7", GetCacheKey(itemsToBeScavenged, 0));
Assert.AreEqual("key3", GetCacheKey(itemsToBeScavenged, 1));
Assert.AreEqual("key8", GetCacheKey(itemsToBeScavenged, 2));
Assert.AreEqual("key4", GetCacheKey(itemsToBeScavenged, 3));
Assert.AreEqual("key5", GetCacheKey(itemsToBeScavenged, 4));
Assert.AreEqual("key", GetCacheKey(itemsToBeScavenged, 5));
Assert.AreEqual("key6", GetCacheKey(itemsToBeScavenged, 6));
Assert.AreEqual("key2", GetCacheKey(itemsToBeScavenged, 7));
}
示例5: WillSortByDateWithSamePriority
public void WillSortByDateWithSamePriority()
{
CacheItem firstItem = new CacheItem("key", "value", CacheItemPriority.Normal, null);
CacheItem secondItem = new CacheItem("key2", "value2", CacheItemPriority.Normal, null);
CacheItem thirdItem = new CacheItem("key3", "value3", CacheItemPriority.Normal, null);
AddCacheItem("key", firstItem);
AddCacheItem("key2", secondItem);
AddCacheItem("key3", thirdItem);
firstItem.SetLastAccessedTime(DateTime.Now + TimeSpan.FromSeconds(200.0));
secondItem.SetLastAccessedTime(DateTime.Now + TimeSpan.FromSeconds(100.0));
thirdItem.SetLastAccessedTime(DateTime.Now + TimeSpan.FromSeconds(150));
SortedList itemsToBeScavenged = new SortedList(inMemoryCache, new PriorityDateComparer(inMemoryCache));
Assert.AreEqual("key2", GetCacheKey(itemsToBeScavenged, 0));
Assert.AreEqual("key3", GetCacheKey(itemsToBeScavenged, 1));
Assert.AreEqual("key", GetCacheKey(itemsToBeScavenged, 2));
}
示例6: UpdateLastAccessedTime
public void UpdateLastAccessedTime()
{
CacheItem historicalItem = new CacheItem("foo", "bar", CacheItemPriority.NotRemovable, null);
historicalItem.SetLastAccessedTime(DateTime.Now - TimeSpan.FromHours(1.0));
string itemRoot = DirectoryRoot + historicalItem.Key;
IsolatedStorageCacheItem item = new IsolatedStorageCacheItem(storage, itemRoot, null);
item.Store(historicalItem);
DateTime now = DateTime.Now;
historicalItem.SetLastAccessedTime(DateTime.Now);
item.UpdateLastAccessedTime(now);
CacheItem restoredItem = item.Load();
Assert.AreEqual(restoredItem.LastAccessedTime, now);
}
示例7: CanUpdateLastAccessedTime
public void CanUpdateLastAccessedTime()
{
CacheItem item = new CacheItem("key", "value", CacheItemPriority.Low, null);
DateTime yesterday = DateTime.Now - TimeSpan.FromDays(1.0);
item.SetLastAccessedTime(yesterday);
backingStore.Add(item);
DateTime now = DateTime.Now;
backingStore.UpdateLastAccessedTime("key", now);
Hashtable retrievedData = backingStore.Load();
CacheItem retrievedItem = (CacheItem)retrievedData["key"];
Assert.AreEqual(now.ToString(), retrievedItem.LastAccessedTime.ToString());
}