/* SharpCached 是一个内存缓存工具
* by yurow @ http://birdshover.cnblogs.com
* 2008-7-29 created
*/
SharpCached V0.6
下载地址:http://files.cnblogs.com/birdshover/SharpCached.zip
有兴趣的朋友,可以和我一起研究,呵呵,不完善的地方期望大家能不吝指正。 本来想在CodePlex开个开源项目的,但是人太笨,用的SvnBridge一直传不上去,郁闷得不弄了,呵呵。
SharpCached是完全用C#开发的,基于.Net Framework 2.0运行的内存缓存服务,Visual Studio 2008项目。
一、实现功能
实现IIS进程外缓存功能,通过Remoting调用。
实现了未命中或者近段时间内未命中结果过期。
实现了限制使用最大内存(程序检测出的和Windows任务管理器不一致,任务管理器中看到使用内存要多一些。)
二、使用服务
编译后文件清单
SharpCached.exe
ISharpCarrier.dll
SharpCached.exe.config
SharpCached.exe.config配置文件说明
<!-- 服务端口 -->
<!-- 最大使用内存,单位M-->
<!-- 存取Key初始数值 -->
<!-- 未命中过期-->
<!-- 服务名-->
注册:sc create "SharpCached" type= interact type= own start= auto binPath= "%cd%"SharpCached.exe"
启动:net start "SharpCached"
三、调用方法
客户端配置文件:
如果是Windows应用程序,把
<!-- 服务器地址 -->
<!-- 连接超时时间 -->
代码加入app.setting中
如果是Web程序,把以上代码加入Web.Config中。
项目引用SharpClient项目和ISharpCarrier项目
示例代码:
DataTable GetTable()
{
SharpCachedAPI api = new SharpCachedAPI();
string key = "key_123";
if (api.IsError)
{
return new DataTable();
}
else
{
if (api.Exist(key))
{
return SharpCachedAPI.Deserialize(api.Get(key));
}
else
{
DataTable dt = new DataTable();
string value = SharpCachedAPI.Serialize(dt);
api.Set(key, value);
return dt;
}
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-413577/ ,如需转载,请注明出处,否则将追究法律责任。