在剝離的過程中,我去除了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
}
}