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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

A few questions about SysGlobalObjectCache

(0) ShareShare
ReportReport
Posted on by 1,673

Hi everyone

I've just got a few questions relating to SysGlobalObjectCache; I know there is good help around, but I'm struggling to find a few answers... (The best source I think is https://blogs.msdn.microsoft.com/axperf/2011/12/29/using-sysglobalobjectcache-sgoc-and-understanding-its-performance-implications/)

Here are some questions:

1) To 'Connect' to or instantiated a SysGlobalObjectCache object, you use

SysGlobalObjectCache sgoc = new SysGlobalObjectCache();

Since a singleton pattern is used, this will always return the current instance of the object. Why then do I see cache being retrieved like this (what's the gain?):

    if(classfactory) 
    { 
            c = classfactory.globalObjectCache(); 
    } 
    else 
    { 
           c = new SysGlobalObjectCache(); 
    } 

2) According the article above, "the SGOC will propagate “clear” calls to all clients and other AOS instances"; I presume Cache is cleared automatically as it gets full. Does the 'clear' method that gets propagated flush per scope, or per key or per value etc? How much cache gets flushed when clear is called?

Thank you

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: A few questions about SysGlobalObjectCache

    I don't know inner working of SysGlobalObjectCache class, but I don't believe it's a singleton; both parts of your code calls the constructor. I think that it all goes to a single dataset in TempDB, so using multiple instances won't give you different data, but it still means consuming more data in memory and more work for AX to create and destroy instances. If you can cache a single instance, you save these resources.

    According to documentation, clear() is "an instance method that clears the cache for one scope". You can use remove() to remove a key and clearAllCaches() to clear the cache for all scopes.

  • BrandonSA Profile Picture
    1,673 on at
    RE: A few questions about SysGlobalObjectCache

    Thanks for the reply Martin

    I do have another question that was meant to be part of this post which is more important than the others...

    I have data that is cached correctly and I can retrieve it, but I can only retrieve it when NOT running on CIL.

    Do you know why NOTHING is returned when running on CIL? Do you know how I can cache data so that it is accessible when called on CIL etc?

  • Verified answer
    Mea_ Profile Picture
    60,284 on at
    RE: A few questions about SysGlobalObjectCache

    Hey BrandonSA,

    It's probably not a singleton, if you read comments from Ganas1 and Michael Fruergaard Pontoppidan you could find that it is AOS specific and has server and client version. So you need to check if it is created and used on same AOS and same tier.

  • Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: A few questions about SysGlobalObjectCache

    Brandon, do you mean that you put data to SCOG in X++ and try to read it in CIL? Or do you do both in CIL?

  • BrandonSA Profile Picture
    1,673 on at
    RE: A few questions about SysGlobalObjectCache

    I mean that I have a class, and in that class is a method which contains something like:

    SysGlobalObjectCache cache = new SysGlobalObjectCache();

    cache.insert(scope, [key], [val]);

    Then there is another method that retrieves the data. Inside of that method there is code like:

    SysGlobalObjectCache cache = new SysGlobalObjectCache();

    if (cache.find(scope, [key]) != conNull())

    {

       [val] = cache.find(scope, [key]);

    }

    When I run this code, val is cached, but when I try to retrieve this val, I can, as long as I'm not running code on CIL. (ie. Unchecked my 'Execute Business Operations in CIL' checkbox in user options'. As soon as I check this box, ie. Run code in CIL, then val isn't retrieved correctly anymore. I ca write a job to retrieve the value and it works, but it isn't retrieved correctly by the code running in CIL.

    So I was wondering if there is a reason for this. Does tier make a difference as ievgen has suggested?

    Thanks

  • BrandonSA Profile Picture
    1,673 on at
    RE: A few questions about SysGlobalObjectCache

    Hi Martin

    I think you answer my question the way you answered someone else here...

    dynamicsuser.net/.../sysglobalcache-thread

  • BrandonSA Profile Picture
    1,673 on at
    RE: A few questions about SysGlobalObjectCache

    Hi Martin

    I thought I understood what the problem is but I'm still running into trouble. What happens is as I explain below. I capture a value from the user on the client side, cache the value using both the client and server versions of classFactory/cache etc, but then can't access the value again while the code is running on CIL.

    Could you please explain to me where I'm misunderstanding this?

    Thanks

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at
    RE: SysGlobalObjectCache CIL

    Hi BrandonSA,

    I'm able to reproduce your issue on AX 2012 R3 CU10. I looked at standard usage of SysGlobalObjectCache and found code you asked about previously, but with interesting comment in a Global class, currentWorker() method:

        //Try put pull from cache first
        if (classfactory)
        {
            sgoc = classfactory.globalObjectCache();
        }
        else
        {
            // Workaround for SysQueryRangeUtil usage under IL
            // the class factory is not initialized in the interpreter
            // when called from IL.This is OK as the global cache is a kernel
            // singleton
            sgoc =  new SysGlobalObjectCache();
        }

    It literally says that cache created outside of IL does not exists in IL, so it is not a bug but "feature".

  • Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: A few questions about SysGlobalObjectCache

    I merged the threads, because Ievgen's reply is very relevant to the first question, which wasn't even mentioned in the new thread.

  • Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: A few questions about SysGlobalObjectCache

    By they way, what are you trying to achieve by using SysGlobalObjectCache in such a way? It looks like you're trying to pass things to another class through global data, which isn't very safe and maintainable.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans