Skip to content

Configuration Settings

David Haney edited this page Mar 8, 2016 · 7 revisions

You can customize the client and host by using settings. Settings can be configured via XML configuration file (in your app.config or web.config), or can be defined programmatically.

Client

Here's an example XML configuration file that documents all settings.

<?xml version="1.0" encoding="utf-8" ?>
<!-- An EXAMPLE Application Configuration that demonstrates how to use and configure Dache Client -->
<configuration>
    <!-- Dache Client Config Section -->
    <configSections>
        <section name="cacheClientSettings"
                 type="Dache.Client.Configuration.CacheClientConfigurationSection, Dache.Client"/>
    </configSections>

    <!-- Cache Client Settings
         hostReconnectIntervalSeconds:
             How often to attempt to re-establish the connection to a 
             disconnected cache host, in seconds. The default is 1. 
             Valid range is greater than or equal to 1.
         hostRedundancyLayers:
             The host redundancy layers. If greater than 0, this indicates 
             how many servers will hold duplicated data per cache host. In 
             practical terms, setting this to greater than 0 creates high 
             availability. The default is 0. Valid range is 0 to 10.
         messageBufferSize:
             The message buffer size. The default is 65536. Valid range is 
             1024 to 524288.
         communicationTimeoutSeconds:
             How long to permit a communication attempt before forcefully 
             closing the connection. The default is 10. Valid range is 
             greater than or equal to 5.
         maximumMessageSizeKB:
             The maximum size of a message permitted, in kilobytes. The 
             default is 10240 (10 MB). Valid range is greater than or 
             equal to 512.
    -->
    <cacheClientSettings hostReconnectIntervalSeconds="1"
                         hostRedundancyLayers="0"
                         messageBufferSize="65536"
                         communicationTimeoutSeconds="10" 
                         maximumMessageSizeKB="10240">
        <!-- Custom logging is optional, but this is how you'd implement it.
             Your custom type must implement Dache.Client.Logging.ILogger -->
        <customLogger type="My.Custom.Logger, My.Custom" />
        <!-- Custom serialization is optional, but this is how you'd implement it. 
             Your custom type must implement Dache.Client.Serialization.IBinarySerializer -->
        <customSerializer type="My.Custom.Serializer, My.Custom" />
        <!-- The list of cache hosts. All clients should have the same list. -->
        <cacheHosts>
            <add address="cacheHost1.your.domain" port="33332" />
            <add address="cacheHost2.your.domain" port="33333" />
            <add address="localhost" port="33334" />
            <add address="127.0.0.1" port="33335" />
            <add address="192.168.1.123" port="33336" />
        </cacheHosts>
    </cacheClientSettings>

    <system.web>
        <!-- Dache Session State Provider -->
        <sessionState cookieless="false" 
                      regenerateExpiredSessionId="true"
                      mode="Custom"
                      customProvider="DacheSessionProvider">
            <providers>
                <add name="DacheSessionProvider"
                     type="Dache.Client.Plugins.SessionState.DacheSessionStateProvider, Dache.Client"
                     writeExceptionsToEventLog="false" />
            </providers>
        </sessionState>

        <!-- Dache Output Caching Provider -->
        <caching>
            <outputCache defaultProvider="DacheOutputCacheProvider">
                <providers>
                    <clear/>
                    <add name="DacheOutputCacheProvider"
                         type="Dache.Client.Plugins.OutputCache.DacheOutputCacheProvider, Dache.Client"/>
                </providers>
            </outputCache>
        </caching>
    </system.web>
</configuration>

Here's some example code to enable Dache to output cache Child Actions in MVC (you'd typically pair this with output caching in the configuration file):

protected void Application_Start()
{
    // Register Dache for MVC Child Action Caching
    var cacheClient = new CacheClient();
    OutputCacheAttribute.ChildActionCache = new DacheMvcChildActionCache(cacheClient);
}

Host

Here's an example XML configuration file that documents all settings:

<?xml version="1.0" encoding="utf-8"?>
<!-- An EXAMPLE Application Configuration that demonstrates how to use and configure Dache Host -->
<configuration>
    <!-- Dache Host Config Section -->
    <configSections>
        <section name="cacheHostSettings"
                 type="Dache.CacheHostService.Configuration.CacheHostConfigurationSection, Dache.CacheHostService"
                 allowExeDefinition="MachineToApplication" />
    </configSections>
    <!-- Cache Host Settings
         port:
             The cache host port. The default is 33333. Valid range is 
             greater than 0.
         messageBufferSize:
             The message buffer size. The default is 65536. Valid range is 
             1024 to 524288.
         communicationTimeoutSeconds:
             How long to permit a communication attempt before forcefully 
             closing the connection. The default is 10. Valid range is 
             greater than or equal to 5.
         maximumMessageSizeKB:
             The maximum size of a message permitted, in kilobytes. The 
             default is 10240 (10 MB). Valid range is greater than or 
             equal to 512.
         cacheMemoryLimitPercentage:
             The cache memory limit, as a percentage of the total system 
             memory. The default is 80. Valid range is 5 to 90.
         compressData:
             Whether or not to compress data via GZip when storing it in 
             the cache. The default is false. Valid options are true and false.
             
    -->
    <cacheHostSettings port="33333"
                       messageBufferSize="65536"
                       communicationTimeoutSeconds="10" 
                       maximumMessageSizeKB="10240"
                       cacheMemoryLimitPercentage="80"
                       compressData="false" />
</configuration>