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 :

RefreshAll - Refresh Cache and resetUsage data combined in one function in Ax2012

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

As a part of troubleshooting, we often clear usage data and clear caches like Refresh Data, Refresh elements and Refresh dictionary. So, for convenience purpose I combined all this functions into a single function namely RefreshAll. CG_RefreshAll class provides this functionality and will be available as a action menuItem on development tools menu.

Path: \Menus\DevelopmentTools\RefreshAll 

Class: CG_RefreshAll

Method:  clearGlobalCaches

public static void clearGlobalCaches()
{
    classFactory.globalCache().flush();
    appl.globalCache().flush();
    infolog.globalCache().flush();

    // if code is running on client, then clean up server cache also.
    if(xGlobal::clientKind() == ClientType::Client)
    {
        CG_RefreshAll::clearServerGlobalCaches();
    }
}

Method: clearGlobalObjectCaches

public static void clearGlobalObjectCaches()
{
    SysGlobalObjectCache::clearAllCaches();

    // if code is running on client, then clean up server cache also.
    if(xGlobal::clientKind() == ClientType::Client)
    {
        CG_RefreshAll::clearServerGlobalObjectCaches();
    }
}

Method: clearManagedCaches

private server static void clearManagedCaches()
{
    try
    {
        // Clears Managed caches
        appl.clearManagedCaches();

        //Clears Metadata Caches
        Microsoft.Dynamics.AX.Framework.Services.Client.MetadataCache::ClearMetadataCaches();
    }
    catch(Exception::CLRError)
    {
        return;
    }
}

Method: clearServerGlobalCaches

private static server void clearServerGlobalCaches()
{
    classFactory.globalCache().flush();
}

Method: clearServerGlobalObjectCaches

private static server void clearServerGlobalObjectCaches()
{
    SysGlobalObjectCache::clearAllCaches();
}

Method: doAODFlush

public static void doAODFlush()
{
    Dictionary::aodFlush();
}

Method: doDataFlush

public static void doDataFlush()
{
    Dictionary::dataFlush();
}

Method: doDictionaryFlush

public static void doDictionaryFlush()
{
    Dictionary dictionary = new Dictionary();
    ;
    dictionary.enumFlush();
    dictionary.typeFlush();
    dictionary.classFlush();
    dictionary.tableFlush();
    dictionary.configurationKeyFlush();
    dictionary.licenseCodeFlush();
    dictionary.securityKeyFlush();
}

Method: main

public static void main(Args args)
{
    // Reset data
    CG_RefreshAll::reset();

    CG_RefreshAll::doDictionaryFlush();
    SysEvent::fireEvent(SysEventType::FlushDictionary);
    if (args && args.parmEnum() == NoYes::No)
        info("@SYS68566");

    // Data flush
    CG_RefreshAll::doDataFlush();
    SysEvent::fireEvent(SysEventType::FlushData);

    if (args && args.parmEnum() == NoYes::No)
        info("@SYS98783");

    // AOD Flush
    CG_RefreshAll::doAODFlush();
    CG_RefreshAll::clearManagedCaches();
    CG_RefreshAll::clearGlobalObjectCaches();

    SysEvent::fireEvent(SysEventType::FlushAOD);

    SysExtensionCache::clearAllScopes();
    CG_RefreshAll::clearGlobalCaches();

    if (args && args.parmEnum() == NoYes::No)
    {
        info("@SYS68564");
    }
}

Method: reset

public server static void reset()
{
    SysLastValue lastValue;
    userId  userId = curUserId();

    ttsbegin;
    delete_from lastValue
        where lastValue.UserId == userId;
    ttscommit;

    info(strFmt("User data has been reset for user: %1", userId));
}

ActionMenuItem: CG_RefreshAll

MenuItem.JPG

Menu: DevelopmentTools

RefreshMenu.JPG

Output:

Output.JPG

Comments

*This post is locked for comments