Exporteren (0) Afdrukken
Alles uitvouwen
Deze inhoud is niet beschikbaar in uw taal, maar wel in het Engels.
1 van 6 hebben dit beoordeeld als nuttig - Dit onderwerp beoordelen

How to: Configure a Cache Client using the Application Configuration File (Windows Azure Shared Caching)

This topic explains how to configure a cache client to use a provisioned Windows Azure Cache. A cache client is any application that accesses the cache programmatically. The configuration can be done programmatically or through an application configuration file. This topic covers the use of the application configuration file. To see how to perform the same configuration programmatically, see How to: Configure a Cache Client Programmatically (Windows Azure Shared Caching).

Much of the cache client programming model for the cloud-based Windows Azure is shared with the on-premises Microsoft AppFabric 1.1 for Windows Server. For more information, see Cache API Support in Windows Azure Cache.

To configure the cache client with an application configuration file

  1. First prepare your Visual Studio 2012 project to use Windows Azure Cache. For more information, see How to: Prepare Visual Studio to Use In-Role Cache (Windows Azure Cache).

  2. On the Management Portal, view the settings for the target cache. For more information, see Managing Caches (Windows Azure Shared Caching).

  3. In the Properties window, note the value of cache Service URL. This is the host name for your Windows Azure Cache. It can also be referred to as the cache endpoint URI.

  4. On the Properties window, also note the value of the cache Authentication Token. This is an ACS key that secures access to your cache.

  5. Click the View Client Configuration button on the toolbar.

  6. In the pop-up Client Configuration window, note the XML snippets. Add these snippets to your projects application configuration file (app.config) or web configuration file (web.config) in the configuration section.

    The configSections element must be the first element in the configuration section. If there is an existing configSections element, just add the copied section within it.

    Note that the sessionState and outputcache elements are only used for ASP.NET applications. You should not copy these into the application configuration file of a non-ASP.NET cache client.

  7. In your application, create a new DataCacheFactoryConfiguration object.

    • Use an empty constructor to load the "default" configuration settings. This also applies if you only have one unnamed dataCacheClient section.

    • Use a string in the constructor to load a named configuration section. For example, the portal automatically provides a dataCacheClient section named "SslEndpoint".

  8. Create a DataCacheFactory object and use the constructor to pass the previously created DataCacheFactoryConfiguration object.

  9. Use the DataCacheFactory object to call GetDefaultCache. This returns a DataCache object that can be used to programmatically access the cache.

The following shows an example of an app.config file configured to use Windows Azure. The actual values in your configuration file will be different.

<?xml version="1.0"?>
    <section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" 
    allowLocation="true" allowDefinition="Everywhere"/>

<!-- Cache exposes two endpoints: one simple and other SSL endpoint. Choose the appropriate endpoint depending on your security needs. -->
  <dataCacheClient name="default">
      <host name="yourcachename.cache.windows.net" cachePort="22233" />

    <securityProperties mode="Message">
      <messageSecurity authorizationInfo="iz8zOmJ0dJBzzzzxa8JxdGJkb281bzxudGF0az9udGxzdGluZi111z8oZS5Ji28lP38jb250Pm9sLmludDMud2luZG93Pi1pb8Qubmx0L1dSQxB2MP45LiZxd25lPii0eDJJZQA5SlZQQUQ2xzIizk8iazlES1P08X8zOFIxZjdzZxp0i3lFQ2FFPSZodJRzOi8xS8JxdGJEb281bzxudGF0az9uxGxzdGluZi5jiz8oZS5pb8QzL8dpbmRxd3MQaz50Lm5ldA==">

  <dataCacheClient name="SslEndpoint">
      <host name="yourcachename.cache.windows.net" cachePort="22243" />

    <securityProperties mode="Message" sslEnabled="true">
      <messageSecurity authorizationInfo="iz8zOmJ0dJBzzzzxa8JxdGJkb281bzxudGF0az9udGxzdGluZi111z8oZS5Ji28lP38jb250Pm9sLmludDMud2luZG93Pi1pb8Qubmx0L1dSQxB2MP45LiZxd25lPii0eDJJZQA5SlZQQUQ2xzIizk8iazlES1P08X8zOFIxZjdzZxp0i3lFQ2FFPSZodJRzOi8xS8JxdGJEb281bzxudGF0az9uxGxzdGluZi5jiz8oZS5pb8QzL8dpbmRxd3MQaz50Lm5ldA==">

The code to obtain a DataCache using the application configuration file is shown below.

// Cache client configured by settings in application configuration file.
DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration("default");
DataCacheFactory cacheFactory = new DataCacheFactory(config);
DataCache defaultCache = cacheFactory.GetDefaultCache();    

// Put and retrieve a test object from the default cache.
defaultCache.Put("testkey", "testobject");
string strObject = (string)defaultCache.Get("testkey");

See Also

Vindt u dit nuttig?
(1500 tekens resterend)
Bedankt voor uw feedback


© 2014 Microsoft. Alle rechten voorbehouden.