zoukankan      html  css  js  c++  java
  • asp.net 分布式缓存

    之前Velocity已被 集成到App Fabric(包含有WCF监控==)中.

    网络Velocity使用大多是针对老版本: 
    老版本的下载地址:  http://www.microsoft.com/en-us/download/details.aspx?id=2517

    这里针对App Fabric做一些说明:

    1. 在VS 2010中使用:

    1) 在App Fabric的安装目录中引用:

    Microsoft.ApplicationServer.Caching.Client.dll

    Microsoft.ApplicationServer.Caching.Core.dll

    image

    Microsoft.ApplicationServer.Caching.Core.dll 是Cache基类库,Cache客户端和服务端都引用该DLL,包含配置库和基类缓存类型。

    Microsoft.ApplicationServer.Caching.Client.dll 包含Cache客户端类库,如连接到Cache cluster存储和检索数据的API接口等等。

    2) Web.config中配置 (可参考:http://msdn.microsoft.com/zh-cn/library/ee790859(v=azure.10).aspx)

    <configSections>
            <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35"/>
        </configSections>
        <dataCacheClient>
            <hosts>
                <host name="Cache服务器主机名" cachePort="22233" />
            </hosts>
        </dataCacheClient>

    3)代码:

               string key = "ApplicationName";
               var dcf = new DataCacheFactory();

               if (dcf != null)
               {
                   var cache = dcf.GetCache("default");    //这个要为Cache服务器中有效的Cache名称, 不然会报错.
                   name = cache.Get(key) as string;
                   if (name == null)
                   {
                       name = "Windows Server App Fabric Cache Lab";
                       cache.Put(key, name);
                   }
               }
              

    image

    在Power shell工具中查询Cache名称的方法:

    image

    2. VS2010中不使用配置文件连接缓存

            DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];
              servers[0] = new DataCacheServerEndpoint("Cache服务器的主机名", 22233);

              // Setup the DataCacheFactory configuration.
              DataCacheFactoryConfiguration factoryConfig = new DataCacheFactoryConfiguration();
              factoryConfig.Servers = servers;

              // Create a configured DataCacheFactory object.
              DataCacheFactory mycacheFactory = new DataCacheFactory(factoryConfig);

              // Get a cache client for the cache "NamedCache1".
              DataCache myDefaultCache = mycacheFactory.GetCache("default");
              myDefaultCache.Put("ApplicationName1", "vvvv");
              object v = myDefaultCache.Get("ApplicationName1");

    常用Power shell命令:

    image

    1. get-command *cache* :查找包含有cache关键字的命令
    image

    2. get-cache: 获取当前服务器的缓存名称

    3. new-cache:新建缓存. 在Cache服务器共享配置文件中会自动添加新的缓存节点
    例: new-cache ‘aaa’
    image

  • 相关阅读:
    Saltstack module apache 详解
    Saltstack module ip 详解
    Saltstack module iosconfig 详解
    Saltstack module introspect 详解
    Saltstack module inspector 详解
    Saltstack module ini 详解
    Saltstack module incron 详解
    Modbus 指令 RS485指令规则
    停车系统对接第三方在线支付平台(二)
    停车系统对接第三方在线支付平台
  • 原文地址:https://www.cnblogs.com/chencidi/p/3706425.html
Copyright © 2011-2022 走看看