web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

SysExtension Caching

(1) ShareShare
ReportReport
Posted on by 1,552
​Hi,

I'm using SyExtension framework. And i can see that there is a method called parmCacheKey
 
1. May i know what does this method mean?

and as u can see I'm using this sysExtension framework inside service class, where I instantiate classA /ClassA classA = ClassA::newFromfieldA(tableA.FieldA);/
2. does that mean class instantiation is cached? if yes what is the benefit? and what is the disadvantage?

3. do i need to flush the cache? if yes how?

 
class EnumAtrribute extends SysAttribute implements SysExtensionIAttribute
{
    Enum enum;

    public void new(Enum  _enum)
    {
        super();
        enum = _enum;
    }
    public str parmCacheKey()
    {
        return classStr(EnumAtrribute)+';'+int2str(enum2int(enum));
    }
    public boolean useSingleton()
    {
        return true;
    }
}

 public service()
{
    public void process(ContractA _contract)
    {
        System.Exception ex;
        query    = _contract.getQuery();
        queryRun = new QueryRun(query);
        while(queryRun.next())
        {
            
            table1 =   queryRun.get(tableNum(Table1));
            table2 =   queryRun.get(tableNum(Table2));
            if(table2) 
            {                
                try
                {
                    ttsbegin;
                    ClassA classA = ClassA::newFromfieldA(tableA.FieldA);
                    if(classA)
                    {
                        classA.run(table2);
                        this.updateTableASuccess(table2, classA.parmTable());
                    }
                    else
                    {
                        throw error(/error/);
                    }
                    ttscommit;
                }
                catch(ex)
                {
                    this.updateTableAFail(tableA, ex.Message);
                }
            }
        }
            
    }
}
 
 

abstract class ClassA
{
        public static ClassA newFromFieldA(Enum _enum)
    {
        EnumAtrribute enumAtrribute = new EnumAtrribute(_enum);
        return SysExtensionAppClassFactory::getClassFromSysAttribute(classStr(ClassA), enumAtrribute);
    }
}
 

I have the same question (0)
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    1. The method returns a key that is used to find a value in the cache.
    2. SysExtensionAppClassFactory will create a new instance. What is cached is a relation between an enum value and a particular class to create, because finding the class is relatively expensive.
    3. Probably not.
  • junior AX Profile Picture
    1,552 on at
     Hi Martin,

    So you mean ClassA classA = ClassA::newFromfieldA(tableA.FieldA); is not cached as the parmCacheKey does sth else?
    and if someone tells me i need to cache instantiating the classA -- is it possible in this scenario?? if yes, then how? 
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    I'm talking about SysExtention framework. ClassA classA = ClassA::newFromfieldA(tableA.FieldA) is your own and if you want to cache something there, such as the value of classA variable, it's up to you to do it. It has nothing to do with parmCacheKey().
     
    I can't tell for sure you whether caching is possible in "this scenario" unless you explain what scenario you mean. In general, you can store the reference somewhere, but it can't cross boundaries of the session. That would require serialization and then putting the same data to a new instance.
  • junior AX Profile Picture
    1,552 on at
    Hi Martin,
     
    By this scenario, then i mean the code i showed you.
     
    I instantiate classA by calling the sysExtension framework. So can you please tell me how can i cache the instantiation for classA by code if parmCacheKey is not related?
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    Instantiation is a process. You can cache a value, not a process. So you can store the value of classA variable somewhere and reuse it, if this what your scenario (still unknown to me) requires and if reusing the same object makes sense at all.
     
    Unfortunately, I can't give you a concrete solutions without knowing the requirements.
  • junior AX Profile Picture
    1,552 on at
    Hi Martin,
     
    So do you mean by caching instantiation of classA, is to define (ClassA classA = ClassA::newFromfieldA(tableA.FieldA)) outside the while loop? -- this is called caching it?
     
    And will i need to flush it after the while loop ends? If yes how?
  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at
    I can't tell you whether using the same instance is the right thing thing or not, because you told me nothing about your requirements, about code in classA, code in updateTableASuccess() and so on. It's also not clear where tableA is populated and why you never use table1. If it's a bug and you actually want to create an instance of ClassA based on table1, doing outside the loop is clearly impossible, because you need information from the query and table1 isn't even defined outside the loop.
     
    Yes, you could call it caching if you want. In my opinion, you should focus more on what you want to achieve and less on terminology.
     
    You don't any flushing of local variables. They ceased to exist at the end of the method (or code block) and the garbage collector will clean up the objects.
  • Suggested answer
    SB-21011618-0 Profile Picture
    3 on at
    The framework handles all of the caching, to save time when creating the instance.
     
    The only time I find that this goes wrong is on a development machine where you change the attribute declaration on the top of the class or rename the class. Even after restarting it will cache the old reference and fail to create an instance.
     
    You can use Refresh AOS elements for this in the UI. But this doesn't always work I used to use SysExtensionCache::clearAllScopes(); if this occurred, e.g.:
     
    class ClassA
    {
         public static ClassA newFromFieldA(Enum _enum)
        {
            EnumAtrribute enumAtrribute = new EnumAtrribute(_enum);
            var instance = SysExtensionAppClassFactory::getClassFromSysAttribute(classStr(ClassA), enumAtrribute);
            if (!instance)
            {
                    SysExtensionCache::clearAllScopes();
                    instance = SysExtensionAppClassFactory::getClassFromSysAttribute(classStr(ClassA), enumAtrribute);
            }
            return SysExtensionAppClassFactory::getClassFromSysAttribute(classStr(ClassA), enumAtrribute);
        }
    }
     
    SysExtensionCache::clearAllScopes(); is now deprecated, and this shouldn't be used - but it does answer the question on how to clear the cache. I think this is what you mean by caching.
     
    In your case, since you don't have a base class with any methods, you could use an interface instead and a class. I'm assuming your ClassA does have an abstract method run though.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 449 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans