在剥离的过程中,我去除了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
}
}
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
}
}