Configuring Caching Policy for an Operation

The DCS Caching policy lets you configure service response caching, which caches service responses in a local database on the client computer. The client proxy returns these cached responses instead of invoking the service. This has the potential advantage of reducing latency while DCS waits for services to respond, and enables a client application to continue functioning if a service goes temporarily offline. DCS can return the cached data for a service until the data has expired. The Caching policy lets you specify how long this expiration period is.

Dd632102.note(en-us,MSDN.10).gifNote:
Currently, DCS supports service response caching for request-response operations only; you cannot implement response caching for conversational operations.

You should only apply service response caching to limited service scenarios, such as statistical information services where the response data has little variation, or services that return configuration information related to the user or workstation, where data is strictly bound to the identity of the user or workstation. You should not attempt to use response caching for personal information services or for services that have responses that vary greatly depending on input parameters. In these cases, stale response data might cause more problems than no data at all.

Service response caching enables time-out functionality, letting you define when the cached data expires and when DCS should ignore cached data and invoke the service directly.

The Caching policy requires several properties for configuration. The following table lists the required properties, and contains a description of each.

Property Name

Description

absoluteExpiration

Determines the time when cached data expires.

enableCaching

Determines whether to apply the Caching policy, and enables administrators to temporarily disable and enable caching.

keyExpression

Represents the properties defined in the Context object that DCS should include in the CacheKey field in the database. The CacheKey derives from a combination of SOAP action, message box, and context properties. If a client application calls the operation from the same context each time, you can leave this blank. If the client application might call the operation from a number of different contexts, you should specify the context properties that the service should store. For example, if your client application might vary the Environment and Organization.Holding properties between communications, set the cache key to Environment;Organization.Holding. (Note that there is no space between the context names.)

OfflineExpiration

Determines a time after the cache expires when DCS might still return cached data if the service instance is offline.

partitionName

A logical name that determines the partition of the caching database in which to store cached data.


Absolute and Offline Expiration

You specify the absolute and offline expiration properties by using a space-delimited format with the following five elements:

  • Minute
  • Hour
  • Day of Month
  • Month
  • Day of Week

The wildcard character (*) denotes that the cache should expire on every interval denoted by that element. You can also use commas to delimit multiple values for the same element. The following table contains several examples of absolute expiration expressions.

Expression

Description

* * * * *

Cache expires every minute of every day.

5 * * * *

Cache expires every five minutes.

* 21 * * *

Cache expires every minute of the 21st hour of every day.

31 15 * * *

Cache expires every day at 15:31.

7 4 * * 6

Cache expires every Saturday at 04:07.

0,15,30,45 * * * *

Cache expires on the hour, and every 15th, 30th, and 45th minute of every hour.


To define Caching policy for an individual operation

  1. In the DCS Management Services Console, expand the Policy Management node, expand the service that contains the required operation, and then expand Operations.
  2. In the left pane, click the operation that you want to configure, right-click the operation, and then click New.
  3. In the Edit Policy dialog box, in the Policy Type list, click Microsoft.ConnectedIndustry.ServiceModel.Application.Policy.CachingPolicy.
  4. In the Direction list, select the message direction on which to specify the policy.
  5. Dd632102.note(en-us,MSDN.10).gifNote:
    For Caching policy, only the wildcard (*) and Response values are acceptable values.

  6. Set the enableCaching property to True to enable caching. You can use this property as a flag to disable the Caching policy temporarily, if necessary.
  7. Set the other properties of the Caching policy, and then click OK.

The following figure shows a sample Caching policy configuration in the DCS Management Services Console.

Dd632102.9883b6f8-dc5f-4d83-abd6-0668f6060740(en-us,MSDN.10).png

Sample Caching policy configuration

In the illustration, the policy specifies cache expiration every two hours, with additional offline expiration of fifteen minutes . The policy includes the Organization.Plant and Environment properties in the database, and specifies the partition name as DcsCache.

In addition to specifying the policy in the DCS Management Services Console, you must configure the client application to import the policy. In the client application configuration file, add the following policy importer element to the system.ServiceModel element.


                    <system.serviceModel>
    ...
    <client>
      <metadata>
        <policyImporters>
        ...
          <extension type="Microsoft.ConnectedIndustry.ServiceModel.ClientCache.ClientCacheBindingElement, Microsoft.ConnectedIndustry.ServiceModel.ClientCache,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35" />
        ...
        </policyImporters>
      </metadata>
    </client>
    ...
</system.serviceModel>

                  

You must also configure a cache partition in the client application configuration file that matches the partition definition in the service policy. To configure a partition, add the element shown in the following example to the configuration file in the dcs.clientCache element. The following configuration matches the policy shown in the previous illustration.


                    <dcs.clientCache>
    <cacheManager>
        <partitions>
        ...
            <partition name="DcsCache" isolationLevel="">
                <store location="Machine" database="CacheDatabaseName" table="CacheTableName" encryption="true"/>
                <expiration absolute="* 2 * * *" sliding=""/>
                <offlineExpiration absolute="15 * * * *" sliding=""/>
            </partition> 
        ...
        </partitions>
    </cacheManager>
    ...
</dcs.clientCache>

                  

For more information, see Configuring a Client Application to Support Response Caching.

Show: