Skip to main content
All docs
V24.1

DashboardConfigurator.DataSourceCacheKeyCreated Event

Occurs when a data source cache key is created. Allows you to manage cache granularity.

Namespace: DevExpress.DashboardWeb

Assembly: DevExpress.Dashboard.v24.1.Web.dll

NuGet Package: DevExpress.Web.Dashboard.Common

Declaration

public event DataSourceCacheKeyCreatedEventHandler DataSourceCacheKeyCreated

Event Data

The DataSourceCacheKeyCreated event's data class is DataSourceCacheKeyCreatedEventArgs. The following properties provide information specific to this event:

Property Description
Key Provides access to the data source cache key.

The event data class exposes the following methods:

Method Description
InvalidateCacheRecord() Invalidates the associated cache record.

Remarks

The Web Dashboard control uses a caching mechanism to optimize data requests. For information on the caching mechanism in the Web Dashboard Control, refer to the following topic: Manage an In-Memory Data Cache.

Each time the dashboard needs data, it creates a cache key. Handle the DataSourceCacheKeyCreated event to access this key or modify it according to your needs. If you need separate cache records for different users or need to refresh the cache record with the latest updates from the data source, handle the event and customize the key as needed.

The next sections describe cache-related scenarios and how to implement them with the DataSourceCacheKeyCreated event.

Remove Parameters from the Cache Key

In the DataSourceCacheKeyCreated event handler, you can remove the parameter collection or only the specified parameters from the cache key. Any value change in the dashboard parameter collection leads to the cache key recreation and excessive data requests. When dashboard parameters are not used to filter data sources, you can choose to exclude them from the cache key to optimize dashboard performance and reduce the number of data requests.

The following snippet deletes the parameter collection from the cache key for the MyDashboard dashboard in the ASP.NET Core Dashboard Control:

configurator.DataSourceCacheKeyCreated += (sender, args) => {
    if (args.Key.DashboardId == "MyDashboard")
        args.Key.Parameters.Clear();
};

Separate Cache for User Groups

Use the CustomData field to add custom information to the cache key. For example, you can add information about users/user groups to the cache key to separate the cache for different users and ensure that users receive the relevant data. The information stored in the cache key cannot be accessed from the client side.

The snippet below adds information about the current user to the cache key in the DataSourceCacheKeyCreated event handler:

configurator.DataSourceCacheKeyCreated += (sender, args) => {
    args.Key.CustomData.Add("currentUser", "Admin");
}

Invalidate Cache Record

Use the InvalidateCacheRecord() method to invalidate (reset) the cache record associated with the current cache key. This way you can ensure that the data is always requested from the server and users get non-cached data with the latest changes.

The following code snippet invalidates the cache record for the sqlDataSource1 data source in the ASP.NET Core Dashboard Control:

configurator.DataSourceCacheKeyCreated += (sender, args) => {
    if (args.Key.DataSourceId == "sqlDataSource1")
        args.InvalidateCacheRecord();
};

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DataSourceCacheKeyCreated event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also