Back to Devexpress

ValidationModule.EnableRuntimeRuleCache Property

expressappframework-devexpress-dot-expressapp-dot-validation-dot-validationmodule-26e761f1.md

latest4.2 KB
Original Source

ValidationModule.EnableRuntimeRuleCache Property

Specifies if the Validation Module caches Rules from custom persistent Rule Sources.

Namespace : DevExpress.ExpressApp.Validation

Assembly : DevExpress.ExpressApp.Validation.v25.2.dll

NuGet Package : DevExpress.ExpressApp.Validation

Declaration

csharp
[DefaultValue(false)]
public bool EnableRuntimeRuleCache { get; set; }
vb
<DefaultValue(False)>
Public Property EnableRuntimeRuleCache As Boolean

Property Value

TypeDefaultDescription
Booleanfalse

true if the Validation Module caches Rules from custom persistent Rule Sources; otherwise, false.

|

Remarks

Built-in Rule Sources query the database each time before validation occurs. You can cache Rules to avoid unnecessary queries. The following code demonstrates how to enable Rule caching for all custom persistent Rule Sources in the platform-agnostic Module:

File : MySolution.Module\Module.cs.

csharp
using DevExpress.ExpressApp.Validation;
// ...
public sealed partial class MySolutionModule : ModuleBase {
    //...
    public override void Setup(ApplicationModulesManager moduleManager) {
        base.Setup(moduleManager);
        //...
        ValidationModule _validationModule = moduleManager.Modules.FindModule<ValidationModule>();
        _validationModule.EnableRuntimeRuleCache = true;
    }
}

To enable or disable caching for a specific persistent Rule Source, subscribe to the CustomizeApplicationRuntimeRules event and specify the EnableRuleCache property:

csharp
using DevExpress.ExpressApp.Validation;
// ...
public sealed partial class MySolutionModule : ModuleBase {
    //...
    public override void Setup(ApplicationModulesManager moduleManager) {
        base.Setup(moduleManager);
        //...
        ValidationModule _validationModule = moduleManager.Modules.FindModule<ValidationModule>();
        _validationModule.EnableRuntimeRuleCache = true;
        _validationModule.CustomizeApplicationRuntimeRules += ValidationModule_CustomizeApplicationRuntimeRules;
    }
    private void ValidationModule_CustomizeApplicationRuntimeRules(object sender, CustomizeApplicationRuntimeRulesEventArgs e) {
        foreach(var ruleSource in e.RuleSources) {
            PersistentContainerRuleSource containerRuleSource = ruleSource as PersistentContainerRuleSource;
            if(containerRuleSource != null) {
                if(typeof(MyPersistentRuleSource) == containerRuleSource.ClassType) {
                    containerRuleSource.EnableRuleCache = false;
                }
            }
        }
    }
}

To clear the Rule cache for all persistent Rule Sources, use the IRuleSet.DropCachedRules method. To clear the Rule cache for a specific persistent Rule Source, find a corresponding PersistentObjectRuleSource or PersistentContainerRuleSource instance in the IRuleSet.RegisteredSources collection and call the IRuleSet.DropCachedRules() method.

See Also

IRuleSource

ValidationModule Class

ValidationModule Members

DevExpress.ExpressApp.Validation Namespace