Managing the Cache

  • Updated

Prerequisites:  A valid RuleApplicationReference
Namespaces: InRule.Runtime
Classes:   RuleSession, RuleApplicationReference, FileSystemRuleApplicationReference,
InMemoryRuleApplicationReference, CatalogRuleApplicationReference
See Also: Retrieving a Rule Application, Creating a RuleSession, Creating a RuleSession with Cache
Retention
, Adding items into the Cache, Iterating items in the cache , Controlling Compilation and Cache
Retention

Compiling a rule application with delegates

When you compile your rule application, you can specify if executable code (delegates) will be compiled at the same time or only when needed. If you select the former, there will be a slower compile time, but the execution time will be faster.

// Compile the RuleApplicationReference, including the executable code (delegates)
ruleAppRef.Compile(CompileSettings.Default);

Setting the degree of parallelism for compilation

You can direct InRule regarding how many threads or cores to use for parallel work when compiling a rule application. This value is a non-negative integer, which you set as follows:

Value

Meaning

0

on; InRule will decide based on the number of cores available

1

off; one thread will be used for all work (default)

n

the number of threads to use

// Compile the RuleApplicationReference, specifying at most two threads or cores
ruleAppRef.Compile(CompileSettings.Create(EngineLogOptions.None, 2));

Note: InRule recommends the default setting (0).

Adding a rule application to the cache

After compiling your rule application, you can speed up future executions by adding it to the rule session cache.

// Add the rule application to the rule application cache
RuleSession.RuleApplicationCache.Add(ruleAppRef);

Removing a rule application from the cache

Of course, you may also remove a rule application from the cache.

// Remove a rule application from the rule application cache
RuleSession.RuleApplicationCache.Remove(ruleAppRef);

Clearing the rule application caches

From time to time, you may want to clear the caches completely. You may do this for the internal cache of a rule application, or for the entire rule session cache.

// Clear internal caches in a rule application reference
ruleAppRef.ClearCompiledFunctions();

// Clear the entire rule application cache
RuleSession.RuleApplicationCache.Clear();

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.