zoukankan      html  css  js  c++  java
  • indeXus.Net Shared Cache 高性能,分布式缓存方案

    一、简介

    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)

  • 相关阅读:
    html meta标签
    随滚动条滚动,动态修改元素class
    获取浏览器长宽自动设置
    SpringMVC常用注解實例詳解2:@ModelAttribute
    SpringMVC常用注解實例詳解1:@Controller,@RequestMapping,@RequestParam,@PathVariable
    Freemarker常用指令使用范例
    Spring整合Freemarker
    SpringMVC配置入門
    再谈深浅拷贝 后端
    转发-react 性能深度探讨
  • 原文地址:https://www.cnblogs.com/tommyli/p/1446849.html
Copyright © 2011-2022 走看看