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


C# CacheItem.SetLastAccessedTime方法代码示例

本文整理汇总了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));
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:25,代码来源:PriorityDateComparerFixture.cs

示例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);
        }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:14,代码来源:SlidingTimeFixture.cs

示例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);
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:17,代码来源:IsolatedStorageCacheItemFixture.cs

示例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));
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:42,代码来源:PriorityDateComparerFixture.cs

示例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));
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:20,代码来源:PriorityDateComparerFixture.cs

示例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);
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:17,代码来源:IsolatedStorageCacheItemFixture.cs

示例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());
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:16,代码来源:DataBackingStoreFixture.cs


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