To ensure that cached objects between multiple Windows Azure role-instances reflect the most recent changes (ie. do not become stale), Adxstudio Portals can be configured to use  Windows Azure Inter-Role Communication to distribute cache invalidation notifications. The scope of the notifications are contained to all worker and web roles under a hosted service.

For cache invalidation settings in a (on premises) web farm or virtual network environment refer to this article instead.

Enabling remote cache invalidation involves creating an Internal Endpoint for the web role deployment.

Creating the Internal Endpoint

 

Follow these instructions for setting up a Windows Azure deployment project for the web role. Open the deployment properties by selecting the web role under the deployment project and pressing alt-enter.

Under the Configuration tab and Instances section, ensure that there is an Instance count value that is greater than 1.

Under the Endpoints tab, (in addition to the default input endpoint on port 80) add an internal endpoint leaving the Public Port empty (dynamic). Take note of the endpoint name (XrmEndpoint) since it is needed when updating the web.config of the web role.

 
 

Alternatively, an endpoint can be added by directly updating the ServiceDefinition.csdef file of the web role deployment.

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="BasicPortalDeploy" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="BasicPortal" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
          <Binding name="Endpoint2" endpointName="XrmEndpoint" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
      <InternalEndpoint name="XrmEndpoint" protocol="http" />
    </Endpoints>
  </WebRole>
</ServiceDefinition>

Configuring the Adxstudio Portals Application

The next step is to update the web role configuration to enable remote cache invalidation.

  1. Configuring your CRM organization for cache invalidation using Web Notification URLs

    First, it is necessary to configure your CRM organization to send cache invalidation notifications to your Adxstudio Portals application. Review the documentation for Web Notification URLs to configure your CRM organization to send cache invalidation notifications to your application.

  2. Configure the application to use the internal endpoint service cache provider

    This custom service provider adds the extended functionality needed to publish cache invalidation messages to the internal endpoints of the role-instances. The internal endpoint name that was specified during endpoint creation should be applied to the internalEndpointName attribute. A custom cache invalidation handler is also required to ensure that messages arriving on the input endpoint are handled correctly.

    <!-- This is an example configuration snippet, with most configuration sections omitted. -->
    <configuration>
    	<configSections>
    		<section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
    	</configSections>
    	<system.web>
    		<httpHandlers>
    			<add verb="*" path="Cache.axd" type="Adxstudio.Xrm.Web.Handlers.CacheInvalidationHandler, Adxstudio.Xrm"/>
    		</httpHandlers>
    	</system.web>
    	<system.webServer>
    		<handlers>
    			<add name="CacheInvalidation" verb="*" path="Cache.axd" preCondition="integratedMode" type="Adxstudio.Xrm.Web.Handlers.CacheInvalidationHandler, Adxstudio.Xrm"/>
    		</handlers>
    	</system.webServer>
    	<microsoft.xrm.client>
    		<serviceCache default="Xrm">
    			<add name="Xrm" type="Adxstudio.Xrm.Services.InternalEndpointOrganizationServiceCache, Adxstudio.Xrm" internalEndpointName="XrmEndpoint"/>
    		</serviceCache>
    	</microsoft.xrm.client>
    </configuration>
    In order to combine the InternalEndpointOrganizationServiceCache with another custom IOrganizationServiceCache implementation, use the "innerServiceCacheName" attribute to chain the custom provider.
    <microsoft.xrm.client>
    	<serviceCache default="Xrm">
    		<add name="Xrm" type="Adxstudio.Xrm.Services.InternalEndpointOrganizationServiceCache, Adxstudio.Xrm" internalEndpointName="XrmEndpoint" innerServiceCacheName="Inner"/>
    		<add name="Inner" type="Adxstudio.Xrm.Services.ContentMapOrganizationServiceCache, Adxstudio.Xrm"/>
    	</serviceCache>
    </microsoft.xrm.client>

At this point, once a change operation occurs on one role-instance, messages are published to all the other role-instances (under the hosted service) that have the specified internal endpoint defined. Each role-instance will then invalidate its local cache item(s) according to the message.