【问题标题】:Setting up azure cache client for local development为本地开发设置 Azure 缓存客户端
【发布时间】:2012-11-15 15:45:18
【问题描述】:

我们的网站在我的 web.config 中都像这样设置:

<dataCacheClients>
    <dataCacheClient name="default">
      <hosts>
        <host name="mysite.cache.windows.net" cachePort="22233" />
      </hosts>

      <securityProperties mode="Message">
        <messageSecurity
          authorizationInfo="{key}">
        </messageSecurity>
      </securityProperties>
    </dataCacheClient>
  </dataCacheClients>

我想对此进行编辑,因此当我在笔记本电脑上进行开发时,我不会访问生产缓存,而是访问笔记本电脑上的缓存。

这对 Google 来说是一个难题(至少对我而言),因为“本地 Azure 缓存”会在 Web 角色上提供缓存。

【问题讨论】:

    标签: .net caching azure


    【解决方案1】:

    您使用的是 Windows Azure 共享缓存,并且您希望在开发时使用一些本地缓存。

    在您的系统中拥有一个抽象缓存层可能会更好,这样您就可以在云和本地之间切换缓存,而不是更改配置。例如,有一个像ICache 这样的接口和GetItemSetItem 等方法。然后你可以让一些类实现这个接口,这些类在内存缓存中用于本地开发,Azure Cache 用于生产。

    在 GitHub 上有一个名为 ServiceStack 的项目,它封装了一些缓存实现,您可以参考 https://github.com/ServiceStack/ServiceStack.Contrib/tree/master/src

    或者,您可以使用新的云服务缓存,它单独提供与您的云服务(Web 角色和工作角色)共置/专用缓存集群。它具有完整的本地仿真器支持,这意味着您无需在本地开发(使用本地缓存仿真器)和生产之间更改任何代码和任何配置。

    有关此云服务缓存的更多信息,您可以参考https://www.windowsazure.com/en-us/develop/net/how-to-guides/cache/

    【讨论】:

      【解决方案2】:

      一种选择是使用 Web.config 转换来更改每个部署的配置文件。我不是这方面的专家,但你可以用谷歌弄清楚。

      另一个选项是在代码中配置缓存。然后,您可以轻松更改每个环境的 .cscfg 文件中的设置。这是代码中的基本配置示例:

      DataCacheFactoryConfiguration cacheConfig = new DataCacheFactoryConfiguration();
      
      //Insert the Authentication Token as shown below
      cacheConfig.SecurityProperties = new DataCacheSecurity(config.AuthToken, config.UseSSL);
      
      int cachePort = (cacheUseSSL ? 22243 : 22233);
      cacheConfig.Servers = new DataCacheServerEndpoint[] { new DataCacheServerEndpoint(cacheHostName, cachePort) };
      cacheConfig.RequestTimeout = TimeSpan.FromSeconds(1);
      cacheConfig.ChannelOpenTimeout = TimeSpan.FromSeconds(45);
      cacheConfig.MaxConnectionsToServer = config.MaxConnections;
      cacheConfig.TransportProperties.ReceiveTimeout = TimeSpan.FromSeconds(30);
      cacheConfig.TransportProperties.ChannelInitializationTimeout = TimeSpan.FromSeconds(10);
      
      var cacheFactory = new DataCacheFactory(cacheConfig);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-20
        • 2021-12-16
        • 1970-01-01
        • 1970-01-01
        • 2015-07-10
        • 2016-10-25
        相关资源
        最近更新 更多