Rule Application Cache Settings

  • Updated

The first time a Rule Application is requested, it must be compiled so the rules engine can execute the rules.  Once a Rule Application is compiled, it is stored in an AppDomain cache for subsequent executions of the application.

The cache, by default, may store 25 Rule Applications at a time.  Each time a Rule Application is requested, the rule engine will first check to see if the Rule Application is in the cache.  When a Rule Application is requested that is not in the cache, it will be retrieved, compiled and then cached.  If the cache limit has been exceeded, one of the Rule Applications in the cache will be removed.

The cache depth can be modified by adding the following to the application configuration file:

<appSettings
  <add key="inrule:runtime:ruleEngine:compiledApplicationCacheDepth" value="25">
</appSettings>        

OR
   <configuration>
     <configSections>

       <section name="inrule.runtime" type="InRule.Runtime.Configuration.RuntimeConfigSectionHandler, InRule.Runtime" />
       ...
     </configSections>
     ...
     <inrule.runtime>
       <ruleEngine compiledApplicationCacheDepth="25" />
       ...
     </inrule.runtime>
   </configuration>

 FileSystemRuleApplicationReference, CatalogRuleApplicationReference and InMemoryRuleApplicationReference all leverage caching.  The methods with which the cache is checked are as follows:

  • InMemoryRuleApplicationReference: A checksum is performed to see if the Rule Application has changed.  This check is more expensive than both the file system check and lightweight Catalog check, which is why it is better to leverage FileSystemRuleApplicationReference or CatalogRuleApplicationReference unless you are modifying rules at runtime.
  • FileSystemRuleApplicationReference: A check is performed to see if the Rule Application file timestamp has been modified.
  • CatalogRuleApplicationReference: When a Rule Application is pulled from the Catalog, it is cached on the client, not the Catalog Service. If the compiled Rule Application is still in the client cache and within the refresh interval when a new RuleSession is created with this reference, the cached Rule Application is used. If the refresh interval has expired, InRule performs a lightweight polling operation to the Catalog to see if a newer version is available. If a new version is available, the latest revision is downloaded, compiled and cached. The following configuration option may be used to change the default refresh interval:
        <appSettings>
           <add key="inrule:runtime:catalogRuleApplication:refreshInterval" value="00:00:30">
        </appSettings>
       OR

<configuration>
           <configSections>
          <section name="inrule.runtime" type="InRule.Runtime.Configuration.RuntimeConfigSectionHandler, InRule.Runtime" />
         ...
         </configSections>
         ...
         <inrule.runtime>
           <catalogRuleApplication refreshInterval="00:00:30" />
           ...
         </inrule.runtime>
        </configuration>

Note: This setting may be overridden via the SDK on a per Rule Application basis via CatalogRuleApplicationReference.RefreshSettings.

By default, the check and recompilation of File System and Catalog Rule Applications will be performed on the main thread. The following configuration option may be used to change the compilation behavior to check and recompile on a background thread: 

    <appSettings>
       <add key="inrule:runtime:ruleEngine:enableBackgroundCompilation" value="true">
    </appSettings> 

  OR
<configuration>
           <configSections>
          <section name="inrule.runtime" type="InRule.Runtime.Configuration.RuntimeConfigSectionHandler, InRule.Runtime" />
         ...
         </configSections>

         ...
         <inrule.runtime>
           <ruleEngine enableBackgroundCompilation="true" />

           ...
         </inrule.runtime>
        </configuration>

Note: This setting may be overridden via the SDK on a per Rule Application basis via FileSystemRuleApplicationReference.EnableBackgroundCompilation or CatalogRuleApplicationReference.EnableBackgroundCompilation. The setting on InMemoryRuleApplicationReference is ignored.

There is some overhead involved when a Rule Application is retrieved, compiled, and added to the cache which will not be present on subsequent RuleSession creations.

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.