You are currently viewing Is gs.cacheFlush() & gs.invalidateCache() Different?

Is gs.cacheFlush() & gs.invalidateCache() Different?

Hello

Welcome to ServiceNow Spectaculars.

This article demonstrates two approaches to deleting cache memory.

Both functions are used for cache clearance on application nodes; however, they have slightly different impact procedures.

Factorsgs.cacheFlush()gs.invalidateCache()
NameIt is called a cache flush.It is called Cache invalidation.
DefintionA cache flush will flush more or less all caches, except for a few, such as the Table Descriptor cache, which is not flushed. It is a kind of standard flush.A cache invalidation flushes 100% of caches and is more impactful than a standard flush.
ExecutionIt is executed by commands such as gs.cacheFlush() or cache.doAn invalidation is executed by the command gs.invalidateCache()
Triggered
Event
The name of the created diagnostic event is ‘cache.flushThe name of the created diagnostic event is ‘cache.invalidate
ProcessingIt processes with 2 records being inserted into sys_cache_flush, with catalogs glide.properties.db and syscache_everythingA record will be inserted into sys_cache_flush with catalog = invalidate_everything
ReportingIt is visible from StatsNow under certain dashboardsIt is not visible from StatsNow under certain dashboards
ParametersIt can accept a parameter, to flush a specific catalog
Eg: gs.cacheFlush(‘syscache_script_include’);
It does not accept any parameters and always invalidates all caches.

Execution Process of gs.cacheFlush()?

Try to execute the below command in a background script.

Command:-
gs.cacheFlush();

Result:-
[0:00:01.468] Script completed in scope global: script
Script execution history and recovery are available here
Starting cache flush
Flushing cache
Flushing Scoped caches
Loading properties from DB
[0:00:00.319] id: dev95794_1[glide.22 (connpid=19045)] for: DBQuery#loadResultSet[sys_properties: ]
Cache flush complete
Loaded the Data Lookup cache in 32 ms
*** Activity.ActivityDocumentTableRepo *** com.glide.activity.core.repo.ActivityDocumentTableRepo_cache_rebuild=[task, x_788387_time_off_request, interaction, cert_follow_on_task, incident, change_request]

Execution Process of gs.invalidateCache()?

Try to execute the below command in a background script.

Command:-
gs.invalidateCache();
Result:-
[0:00:02.859] Script completed in scope global: script
Script execution history and recovery available here
Invalidating cache