拜年:indeXus.Net Shared Cache - 高性能,分布式缓存方案

昨天在codeplex.com上闲逛,偶遇到个好东西,提来给大家拜年。

-----------------------------------------------------------------------------------------

一、简介

出处:http://wuchang.cnblogs.com

indeXus.Net SharedCache是高性能的、分布式的内存对象系统,用于在动态WEB或Win应用程序中减少数据库的负责,提高访问速度。

SharedCache 全部的代码都是用c#写的,100% DotNet原生态。

先来看一下SharedCache 的几种方式:

1.Distributed Caching - partitioned

Partitioned 

2.Replicated Caching

Replicated Caching

3.Single Instance Caching

Single Instance Caching

 

二、小试牛刀

1.服务端

全部源码可以在SharedCache项目网站(http://www.codeplex.com/SharedCache)下载。

方案中中有7个项目

solution

可以直接在vs2008 中打开编译。

但压缩包中缺少ICSharpCode.SharpZipLib.dll,编译前䉣准备好这个。

编译成功后MergeSystem.Indexus.WinService\bin\Debug目录的文件

files

job_install.bat / job_uninstall.bat  安装/卸载windows服务

job_startService.bat / job_stopService.bat 开启/停止服务 

job_Console.bat 在控制台中加载服务。

如果不想安装到Windows服务中,直接用Job_Console.bat启动即可,默认监听端口是48888(在MergeSystem.Indexus.WinService.vshost.exe.config中配置),

console

2.测试程序

新建一个控制台程序,添加MergeSystem.Indexus.WinServiceCommon的引用。测试代码如下:

 

using System;
using MergeSystem.Indexus.WinServiceCommon.Provider.Cache;

namespace ConsoleApplication1
{
   
class Program
    {
       
static   void Main( string [] args)
        {
            User[] data
=   new [] { new User{ Name = " user1 " ,Age = 20 },
           
new User{ Name = " user2 " ,Age = 1 },
           
new User{ Name = " user3 " ,Age = 22 }
            };

           
foreach (var item in data)
            {
                IndexusDistributionCache.SharedCache.Add(item.Name, item);
            }

            Console.WriteLine(
" count={0} " , IndexusDistributionCache.SharedCache.Count);

            User user
= IndexusDistributionCache.SharedCache.Get < User > ( " user2 " );

            Console.WriteLine(
" name={0},age={1} " , user.Name, user.Age);

            Console.WriteLine(
" press any key to exit. " );
            Console.ReadKey();
        }
    }

    [Serializable]
   
public   class User
    {
       
public   string Name { get ; set ; }
       
public   int Age { get ; set ; }

    }
}

App.config中配置

<? xml version="1.0" encoding="utf-8" ?>
< configuration >
   
< configSections >
     
< section name ="indexusNetSharedCache" type ="MergeSystem.Indexus.WinServiceCommon.Configuration.Client.IndexusProviderSection, MergeSystem.Indexus.WinServiceCommon" />

   
</ configSections >

 
< indexusNetSharedCache defaultProvider ="IndexusSharedCacheProvider" >
   
< servers >
    
< add key ="SrvZh03"   ipaddress ="127.0.0.1" port ="48888"   />
   
</ servers >
   
< providers >
     
< add
       
name ="IndexusSharedCacheProvider"
        type
="MergeSystem.Indexus.WinServiceCommon.Provider.Cache.IndexusSharedCacheProvider, MergeSystem.Indexus.WinServiceCommon"
          
>
     
</ add >
   
</ providers >
 
</ indexusNetSharedCache >
</ configuration >

测试程序运行结果

console test

服务端响应:

console info

要注意的是,缓存的对象必需是可序列化的(Serializable)

出处:wuchang.cnblogs.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值