讓自己的架構實現緩衝的功能

來源:互聯網
上載者:User

在剝離的過程中,我去除了BackingStoreImplementations下的大部分,去除了Instrumentation的全部<用於做日誌還有計數器之類用途的> 去除了原本必須依賴設定檔才能使用的。
現在的功能只能依賴記憶體來作緩衝,修改常量來影響緩衝行為。
但是不依賴設定檔,可以很達到簡單的融入自己的架構。
由於昨天沒時間測試遷移的代碼,所以沒有發布代碼
目前只支援 AbsoulteTime SlidingTime NeverExpire方式的,至於FileDependency的需要自己整合一個Action,所以沒做測試,也沒去研究移植後的代碼是否可行。
http://files.cnblogs.com/wildfish/Caching.rar
今天測試了一下,覺得沒什麼問題。
順便發布了測試代碼using System;
using System.Data;
using NUnit.Framework ;
using FishSky.SystemFrameWork.Caching;
using FishSky.SystemFrameWork.Caching.Expirations;
using FishSky.SystemFrameWork.Base;
using FishSky.Data.Base ;
using System.Threading;
namespace FishSkyTest.SystemFrameworkTest
{
    /**//// <summary>
    /// CachingTesting 的摘要說明。
    /// </summary>
    [TestFixture]
    public class CachingTesting
    {
        private CacheManager manager=CacheFactory.GetCacheManager();
        private static string KeyWordToStore1="KeyWordToStore1";
        private static string KeyWordToStore2="KeyWordToStore2";
        private static string KeyWordToStore3="KeyWordToStore3";
        private static string KeyWordToStore4="KeyWordToStore4";

        public CachingTesting()
        {
        
        }

        SetUp#region SetUp

        [SetUp]
        public void SetUp()
        {
            manager.Flush();
        }

        #endregion

        TestTimeSpanCacheAddRemove#region TestTimeSpanCacheAddRemove

        [Test]
        public void TestTimeSpanCacheAddRemove()
        {
            Console.WriteLine("Testing start.");

            WhereField wf=new WhereField("Penavicoxm",typeof(string),20,true,false);
            wf.FieldValue ="kevin";

            SetField sf=new SetField("PenavicoxmSet",typeof(string),30,false);
            sf.FieldValue ="kevin.chin";

            

            TimeSpan timespan1=new TimeSpan(0,10,0);
            TimeSpan timespan2=new TimeSpan(0,0,20);

            
            
            SlidingTime expiretime1 =new SlidingTime(timespan1);
            SlidingTime expiretime2 =new SlidingTime(timespan2);
            

            manager.Add(CachingTesting.KeyWordToStore1,wf,CacheItemPriority.Normal,null,expiretime1);
            manager.Add(CachingTesting.KeyWordToStore2,sf,CacheItemPriority.Normal,null,expiretime2);
            

            WhereField cachedWf=manager.GetData(CachingTesting.KeyWordToStore1) as WhereField;
            Assert.IsNotNull(cachedWf);
            Assert.AreEqual(cachedWf.FieldValue.ToString(),"kevin");

            manager.Remove(CachingTesting.KeyWordToStore1);
            

            object obj=manager.GetData(CachingTesting.KeyWordToStore1);
            Assert.IsNull(obj);

            Console.WriteLine("Testing will sleep 180 seconds.");

            Thread.Sleep(180000);

            object nullCache2=manager.GetData(CachingTesting.KeyWordToStore2);
            Assert.IsNull(nullCache2);

            Console.WriteLine("Testing finished!");
        }

        #endregion

        TestAbsoluteTime#region TestAbsoluteTime

        [Test]
        public void TestAbsoluteTime()
        {
            SetField sf2=new SetField("PenavicoxmSet",typeof(string),30,false);
            sf2.FieldValue ="kevin.chin";

            //each time u wanna test,must change the time to one minute before the test
            DateTime refreshDateTime=new DateTime(2006,1,12,10,41,20);
            AbsoluteTime expiretime3=new AbsoluteTime(refreshDateTime);

            manager.Add(CachingTesting.KeyWordToStore3,sf2,CacheItemPriority.Normal,null,expiretime3);

            Assert.IsNotNull(manager.GetData(CachingTesting.KeyWordToStore3));
            Thread.Sleep(120000);
            Assert.IsNull(manager.GetData(CachingTesting.KeyWordToStore3)) ;
            
        }

        #endregion

        TestNeverExpired#region TestNeverExpired

        [Test]
        public void TestNeverExpired()
        {
            SetField sf2=new SetField("PenavicoxmSet",typeof(string),30,false);
            sf2.FieldValue ="kevin.chin";

            manager.Add(CachingTesting.KeyWordToStore4,sf2,CacheItemPriority.Normal,null,null);

            Assert.IsNotNull(manager.GetData(CachingTesting.KeyWordToStore4));

            Thread.Sleep(120000);

            Assert.IsNotNull(manager.GetData(CachingTesting.KeyWordToStore4));
    
        }

        #endregion
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.