Rule Application Cache Characteristics and Significance
When a rule application is loaded for first time execution, the rule application is compiled and then cached in the AppDomain. Subsequent requests for the rule application will pull from the AppDomain cache, providing faster access to the rule application. The compile and caching process is sometimes referred to as the cold start.
Note: When calling the rule engine as a service (either with SDK, proxy objects or a custom service wrapper), the "client" will be the service itself.
Additional Information
- The FileSystemRuleApplicationReference, CatalogRuleApplicationReference and InMemoryRuleApplicationReference all leverage caching.
- Each rule application type will check to see if there have been changes made to the rule application (or if there is a new revision of the rule application in the case of the CatalogRuleApplicationReference) and will recompile and cache the rule application if there are changes.
- By default, 5 rule applications will be stored in the cache. To modify the the cache size, see Compiled Application Cache Depth
- Any time the AppDomain shuts down (e.g. IISReset or AppPool settings such as Recycling or Performance settings), the cache is cleared.
- Methods are available on the SDK to support advanced scenarios that require custom management of the rule application cache. Please see the SDK file help sections Managing the Rule Application Cache and Controlling Compilation and Cache Retention for more details.
Catalog Specific Caching Behavior
- When a rule application is pulled from the Catalog, it is cached on the client, not the Catalog Service.
- When a rule engine request executes and the rule application is not in the cache, it is pulled from the Catalog. It is then compiled and saved in the cache for a given "refresh interval".
- If the refresh interval has expired, a lightweight poll to the Catalog is performed when the next RuleSession is created to determine whether a newer revision of the rules exists. If a newer revision does not exist, the cached Rule Application is reused.
- If the Rule Application is in the cache, then the cached version is always reused until the refresh interval expires. The default refresh interval is 30 seconds. The refresh interval can be overridden by calling the SetRefresh method on the CatalogRuleApplicationReference. See the example below:
// Instruct the engine to work with the latest version of the rule application
var ruleApp = new CatalogRuleApplicationReference("MyRuleApp");
// Override the default refresh interval to check for latest rule version from 30 seconds to 10 minutes
ruleApp.SetRefresh(TimeSpan.FromMinutes(10));
To prevent the main thread from blocking while the Catalog is polled and the latest revision of the Rule Application is compiled, the poll and compile may be performed on a background thread while the main thread continues to use the previously cached revision of the Rule Application:
// Instruct the engine to work with the latest version of the rule application, but check for a new revision on a background thread after the refresh interval has expired
var ruleApp = new CatalogRuleApplicationReference("MyRuleApp", true);
Comments
0 comments
Please sign in to leave a comment.