Scoped Caches
Squid utilizes ServiceNow Scoped Caches to minimize the overhead caused by repeatedly retrieving largely stable data from the database.
What does Squid cache?
Squid currently caches
-
configured References, i.e., the content of the tables
x_a46gh_squidx_referencesx_a46gh_squidx_references_predefined.
-
view metadata. Squid retrieves metadata (column name, data type, etc.) of all views used in configurations.
We expect to cache all configuration data in the near future.
What do we have to do?
Squid caches are installed and configured by default.
You can check if they are working by adding the query parameter metadata
{
"metadata": {
...,
"config_cache": {
"view_metadata": {
"hits": 11,
"misses": 0
},
"references": {
"hits": 9,
"misses": 0
}
},
...
},
...
}
What if we don't see any cache hits?
If you consistently do not see any cache hits, please check your instance for the following entires:
Scoped Caches (sys_scoped_cache)
These define the scoped caches.
Scoped Cache Table Pairs (sys_scoped_cache_table_pair)
These define which tables trigger a cache invalidation.
System Property useScopedCache
This is the flag that enables the scoped cache.
Why is caching necessary?
A fairly simple request can cause Squid to trigger 5–15 SQL queries for reference configurations as well as retrieving metadata for 10–20 views. This will easily cost 50–100ms. This is a significant overhead especially in the context of a devOps single entity request that should take less than 100 ms overall. (You won't notice any delay when executing a massive request taking 5–10 minutes, but those are not our only use cases.)
Caching reduces execution time by about 100 ms as well as reducing database load per request.
ServiceNow does not allow script includes to hold state. A script include is reinitialized on each and every call.
Squid is such a script include. The only way to hold data between requests is to use a scoped cache.