Kashperuk Ivan: Tutorial: Caching display methods
Caching is an important part of the Microsoft Dynamics AX application. It allows us to significantly speed up certain processes by avoiding redundant round trips to the server and the database. Display/Edit methods are a good example of where caching is helpful, as it significantly increases the overall responsiveness of a form.
In AX 2012 R3 there are a number of ways you can specify that a display method needs to be cached. Below is a list, as well as a brief description and an xpo with a tutorial form to show the various options.
All cached data methods are calculated and cached in executeQuery of the data source they belong to. That is why it is important to call the above method in the init() of the data source, once the data source is initialized, but the data hasn't been retrieved yet. The optional second parameter controls whether or not the display method value should be refreshed when data is written to DB
On top of the above, I would also like to mention a few other things.
You can download the xpo project with the tutorial from my OneDrive.
Upon opening the form in the project, some data will be pulled into the form. More specifically, the first 3 items/customers/vendors/sites/warehouses. For each of them a display method is present, and one of the above approaches is used to cache it.
None of the display methods are cached. As you can see, nothing extra was done in executeQuery of the main data source, but itemName was cached for all 3 records for the read-only data source, as the control has "Cache data method" property set to Auto. This happens even though the tab page is not the active one, so it wasn't really yet necessary to calculate these values. Maybe the user won't even navigate to that tab page. You should consider this carefully when designing a form, and always aim at increasing the overall responsiveness of a form by only executing the appropriate display methods.
Step 2 and 3
inventSiteName and vendName were cached (through one of the options above). As you can see, now their values are calculated once for each of the records shown. InventLocationName and custName are still not cached.
Clicking on Refresh result button will show any extra calls to the display methods since the form started. As you’ll quickly notice, the non-cached methods are being called every time something hints at covering up the value of the control, or rather every time AX thinks it needs to recalculate the value, which is VERY OFTEN. That should make it pretty clear how useful caching is for display methods.
Now inventLocationName was also cached, and the only method that is remaining and not cached is custName. You can see how more and more methods are executed in one batch on the server as part of the executeQuery method on the data source.
As the last step, I have added 2 standalone controls that show the Title fields of the main data source table, and started logging the time method caption is invoked. As I have written above, titleFields and parentTitleFields are cached automatically, but you can't really see it, as it is not possible to override it. caption is the closest you can get to it, so I figured it's worth showing that. You can see the method is evaluated right after all data source queries have executed (as it relies on the currently selected record). It is evaluated first time based on the selected data source record, and then again when focus actually goes to the grid, so that the first record is explicitly selected. It will be invoked again whenever the active record changes. Note that unlike custName method, it does not get constantly refreshed.
Play around with the form and let me know if you have any questions or comments.
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
|За это сообщение автора поблагодарили: Logger (1).|
Ваня, большое спасибо за обучалку!
Даже если вещь тривиальная и понятная - то все равно пример использования никогда не бывает лишним.
Спасибо за то, что делаешь примеры.
Возможно сделать все. Вопрос времени
|ax2012, display method, полезное|
|Kashperuk Ivan: Tutorial: refresh, reread, research, executeQuery - which one to use?||Blog bot||DAX Blogs||20||04.04.2017 13:23|
|Kashperuk Ivan: Tutorial: InventDimCtrl_Frm classes and the amazing things you can do with their help||Blog bot||DAX Blogs||0||18.01.2015 08:18|
|Caching display methods with Client modifier||Blog bot||DAX Blogs||0||18.09.2013 23:13|
|Kashperuk Ivan: Tutorial: AX 2012 - Invalid field access or Accessing unretrieved fields||Blog bot||DAX Blogs||0||29.10.2011 05:18|
|Kashperuk Ivan: Lookup methods tutorial + custom list lookup implementation||Blog bot||DAX Blogs||0||04.05.2009 14:05|
|Опции темы||Поиск в этой теме|