The CreatorCon Call for Content is officially open! Get started here.

how to clear the cache in scoped application using script?

Community Alums
Not applicable

hi Developers I am able to clear the cache via script using ga.cacheFlush(); in global scope but same cannot use in scoped Application

Can anyone suggest any alternative for clearing cache via code in scoped Application

thanks in advance

Regards 

harsha

10 REPLIES 10

MrMuhammad
Giga Sage

Hi Harsha,

you need to us gs.cacheFlush() in script include [created in global scope] and call that script include from scoped app. That will clear the cache.

In the script call it like below

var SI = new global.cacheUtil().clearCache();

Script include

name - cacheUtil 

Accessible from - All application scopes

var cacheUtil = Class.create(); //(auto generated)
cacheUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  clearCache: function() {

    gs.cacheFlush();

  }
    },

});

Thanks,

Sharjeel

Regards,
Muhammad

MrMuhammad
Giga Sage

In addition to the above response,  I would add a couple of recommendations here.

gs.cacheFlush() will clear cache globally for all the users not just for the currently logged in user. So it is recommended not to use in the script that will execute continuously i.e. BR, client scripts [glideAjax], etc.  Also, see Chuck Tomasi's response on the below thread to understand when and when not to clear the cache.

https://community.servicenow.com/community?id=community_question&sys_id=d45643e1db1cdbc01dcaf3231f96...

 

Regards,
Muhammad

Community Alums
Not applicable

Sure Muhammad,I will check on that.

regards 

Harsha

Thank you for the update. Let me know if you got any questions. 

Regards,
Muhammad

Megha Padale
Giga Guru

Hi Harsha,

Check below links, it will help you

https://community.servicenow.com/community?id=community_article&sys_id=0eb79438db0e93804fc2f4621f961...

https://community.servicenow.com/community?id=community_question&sys_id=b1a24f21dbd8dbc01dcaf3231f96...

If my answer helped you in any way, mark answer as helpful and correct.

Thanks and regards,

Megha