How to use GlideCacheManager?

Peter64
Tera Contributor

I see that the GlideCacheManager class is used in some scripts. Is there any relevant documentation on how to use it, or can you tell me some methods related to it?

6 REPLIES 6

Hi @cynlink1 

ServiceNow has internally different caches to speed up access to data like ACLs or System Properties without requesting the database each time.

But if you change an ACL some caches are cleared to be built again from scratch during the next cache access.

Kind regards
Maik

BillMartin
Mega Sage

hi @Peter64 , i am not a fun of GlideCacheManage since ServiceNow is using Rhino Engine, it is another layer utilizing the JAVA api...... Depending on your requirement, I have a created this singleton design pattern that allows you to cache in a single instance.

 

var CacheHandler = (function() {
var instance;

function createInstance() {
var cache = {};

return {
get: function(key) {
return cache.hasOwnProperty(key) ? cache[key] : null;
},

set: function(key, value) {
cache[key] = value;
},

has: function(key) {
return cache.hasOwnProperty(key);
},

clear: function() {
cache = {};
gs.info("[CacheHandler] Cache cleared.");
}
};
}

return {
getInstance: function() {
if (!instance) {
instance = createInstance();
}
return instance;
}
};
})();
 
Screenshot 2025-04-17 at 10.22.13 AM.png

 

Screenshot 2025-04-17 at 10.22.33 AM.png