ASPxDashboard.DataSourceCacheKeyCreated Event
Occurs when a data source cache key is created. Allows you to manage cache granularity.
Namespace: DevExpress.DashboardWeb
Assembly: DevExpress.Dashboard.v24.2.Web.WebForms.dll
Declaration
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 code snippet deletes the parameter collection from the cache key for the MyDashboard dashboard in the ASP.NET Web Forms Dashboard Control:
protected void DataSourceCacheKeyCreated(object sender, DataSourceCacheKeyCreatedEventArgs 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 user groups to the cache key to use separate cached datasets for different users. Note that 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:
protected void DataSourceCacheKeyCreated(object sender, DataSourceCacheKeyCreatedEventArgs args) {
args.Key.CustomData.Add("userGroup", "Sales");
}
Invalidate the Cache Record
Use the InvalidateCacheRecord() method to invalidate (reset) the cache record associated with the current cache key. This way you can ensure that data is always requested from the server and users have access to the latest changes.
The following code snippet invalidates the cache record for the sqlDataSource1 data source in the ASP.NET Web Forms Dashboard Control:
protected void DataSourceCacheKeyCreated(object sender, DataSourceCacheKeyCreatedEventArgs args) {
if (args.Key.DataSourceId == "sqlDataSource1")
args.InvalidateCacheRecord();
}