Tuesday, August 27, 2019

display method caching in Dynamics Ax

I just got into a problem with a display method which let me dig a bit more on the subject. Let me share with you, maybe is nothing new, but worth remembering.

I created my method on the table like this:

[SysClientCacheDataMethodAttribute(true)]
public display MYD_AnnualContractValue contractValue()
{
    MYD_AnnualContractValue value;

    value = // code to get the value...

    return value;
}
first one consideration (from http://www.axaptapedia.com/CacheAddMethod)

Performance considerations

When caching is enabled for a display or edit method, that result of the method will be calculated on the AOS and passed through to the client with the result set. In general, this is faster than calling the method directly from the client, on demand, as it reduces client-server calls.

This makes good sense when a display method is used as part of a grid, but in other circumstances it is important to gauge whether the cost of having the method calculated every time is worth the reduction in client-server calls. An uncashed display method is triggered only when the control is visible, so it can be better to not use caching for display methods bound to controls on tab pages which are rarely viewed.

Attribute SysClientCacheDataMethodAttribute set to true if you want it updated when a record is saved

Look in \Classes\SysClientCacheDataMethodAttribute\new and see that when you set true the display cache is update on record save. When you set as false it is not. meaning that the display method on the form will not change on update until you close and open the form again

refresh the display when you modify a record (before you save it)

you have two options:

OPTION 1

the simplest option is just to remove the SysClientCacheDataMethodAttribute completely

//[SysClientCacheDataMethodAttribute(true)] //Enrico: do not use cache so the value changes immediately without need to save.
public display MYD_AnnualContractValue contractValue()
{
    //
}

which might make sense especially if this method is not expected to go inside a grid.

OPTION 2

use cacheCalculateMethod as explained in this post: https://smrithisomanna.blogspot.com/2008/12/using-cacheaddmethod.html
which works also if you set the cache on the table rather then using the cacheAddMethod on the datasource.

under the datasource on the field/s that is/are triggering the display method to be updated override the modify method like this:

image

public void modified()
{
    super();
    MyTable_ds.cacheCalculateMethod(tablemethodstr(MyTable, contractValue));
}
in this way you can leave the caching attribute on the table display method so that it is always cached by default and force a refresh programmatically.

No comments:

Post a Comment