Skip to main content
.NET Framework 4.5.2+

XafApplication.EnableModelCache Property

Specifies if the Application Model cache designed to improve the startup speed and performance is enabled.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v22.2.dll

NuGet Package: DevExpress.ExpressApp


public bool EnableModelCache { get; set; }

Property Value

Type Default Description
Boolean false

true, if the Application Model is cached; otherwise, false.


If your WinForms application starts slowly, you can speed up the startup using the EnableModelCache property. When it is set to true, the Application Model content is cached to a file when the application is first launched, and recovered on subsequent runs. This property has effect in the production environment when the debugger is not attached (see Debugger.IsAttached). By default, EnableModelCache is set to false. To change this property value, add the following code to the Program.cs (Program.vb) file, before the XafApplication.Setup method is called.

static void Main() {
    winApplication.EnableModelCache = true;

As a result, Nodes Generators and Generator Updaters will be executed and the Model.Cache.xafml cache file will be created only when the application is started for the first time. Note that the first startup can take more time than usual. However, the time taken by subsequent startups will be reduced, because the Application Model content will be recovered from the cache. The cache is recreated when the version of any application module is incremented.

The Model.Cache.xafml file name is specified by the static ModelStoreBase.ModelCacheDefaultName field.

When the cache is in use, consider the following.

  • Only the ModelNodeGenerator.UpdateCachedNodes method is called for all Nodes Generators. If you need to create extra nodes after the Application Model is recovered from the cache file, override this protected method.
  • Only the ModelNodesGeneratorUpdater`1.UpdateCachedNode method is called for all Generator Updaters. If you need to update a certain node after it has been recovered from the cache file, override this method.

Customize the Cache Location and Behavior

By default, the Model.Cache.xafml file is located in the application folder. You can change its path using one of the following approaches.

  • Override the GetModelCacheFileLocationPath method in XafApplication descendant.
  • Use the ModelCacheLocation key in the configuration file (App.config).

        <!-- ... -->
        <add key="ModelCacheLocation" value="CurrentUserApplicationDataFolder"/>
        <!-- ... -->

To customize the cache behavior, use static fields of the ModelCacheManager class, or inherit this class and pass the descendant to the XafApplication.CreateCustomModelCacheManager event.

When and Why is the Cache Updated?

To determine whether or not the cache file needs to be updated on startup, an XAF application compares the loaded modules versions with versions from the ModulesVersionInfo file. This file stores versions for all modules which were used in the previous application launch. If there are no updated modules, the application loads the cache file; otherwise, the cache file is recreated. Modifying the cache options using the ModelCacheManager class does not enforce an immediate cache update. So, if you see that your customizations have no effect, ensure that at least one of your module versions is incremented, or delete the cache file manually.

Enable Model Cache in ASP.NET Web Forms Applications

By default, the EnableModelCache property has no effect on ASP.NET Web Forms applications. To enable the cache, overwrite the GetModulesVersionInfoFilePath method in your WebApplication descendant (in the WebApplication.cs (WebApplication.vb) file), and specify the location of the ModulesVersionInfo file that stores the module versions. Then, override the GetModelCacheFileLocationPath method to specify the cache file location.

See Also