zoukankan      html  css  js  c++  java
  • 微软分布式缓存AppFabric(Velocity)-开发篇(一)开发环境准备

    配置好缓存群集时,在windows services 中启动名为:Microsoft project code named “Velocity”的服务,该服务默认不会自动启动

    1. 将Volocity的程序集copy到开发机器上。程序集位于Velocity的安装目录。程序集如下:

    CacheBaseLibrary.dll,

    ClientLibrary.dll,

     FabricCommon.dll,

     CASBase.dll.

    2.在VS的工程中添加以上程序集的引用

    3.配置缓存客户端的xml配置文件一般为.config文件,或直接在代码里指定配置

    选择用Routing Cleing或Simple Client,选择Routing Client会获得最佳的性能。

    Demo:

    下面是一个Routing Client的配置示例。示例中未启用本地缓存,但使用了两个缓存主机:CacheServer1和CacheServer2

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      
      <!--configSections must be the FIRST element -->
      <configSections>
        
        <!-- required to read the <dataCacheClient> element -->
        <section name="dataCacheClient"
           type="Microsoft.Data.Caching.DataCacheClientSection,
           CacheBaseLibrary"
           allowLocation="true"
           allowDefinition="Everywhere"/>
        
        <!-- required to read the <fabric> element, when present -->
        <section name="fabric"
           type="System.Data.Fabric.Common.ConfigFile,
           FabricCommon"
           allowLocation="true"
           allowDefinition="Everywhere"/>
        
      </configSections>
      
      <!-- routing client-->
      <dataCacheClient deployment="routing">
    
        <!-- (optional) specify local cache 
        <localCache
          isEnabled="true"
          sync="TTLBased"
          objectCount="100000"
          ttlValue="300" />
        -->
    
        <!--(optional) specify cache notifications poll interval 
        <clientNotification pollInterval="300" />
        -->
        
        <!-- cache host(s) -->    
        <hosts>
          <host
             name="CacheServer1"
             cachePort="22233"
             cacheHostName="DistributedCacheService"/>
          <host
             name="CacheServer2"
             cachePort="22233"
             cacheHostName="DistributedCacheService"/>
        </hosts>
      </dataCacheClient>
    </configuration>

    下面代码演示如何在代码中指定配置

    //declare array for cache host(s)
    DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
    
    //specify cache host(s)
    servers[0] = new DataCacheServerEndpoint("CacheServer2", 
                            22233, "DistributedCacheService");
    
    //specify cache client configuration
    DataCacheFactory mycacheFactory 
        = new DataCacheFactory(servers, true, false);
    
    //get cache client for cache "NamedCache1"
    DataCache myDefaultCache = mycacheFactory.GetCache("NamedCache1");
  • 相关阅读:
    Java文件操作大全
    struts2整合spring3整合成功但是spring无法注入
    简单理解xFire webservices
    分享几个常用过滤器
    mysql导sql脚本
    开源Jbpm4.4+ssh2+oracle10实现表单、流程自定义开发流程业务
    关于搭建FTP服务器
    chrome标签同步神器插件集装箱!
    记录java接口自动化模板优化
    java之封装日期工具类DateUtils
  • 原文地址:https://www.cnblogs.com/xuf22/p/2143788.html
Copyright © 2011-2022 走看看