Caching is one of the methods which systems use to improve performance and respond to requests rapidly.
In a Business Central system, caching is done at two levels:
- Business Central Server Instance Data Cache
- SQL Server Data Cache.
Whenever a User requests data from Business Central, it firsts check whether
- The data is available in the Server Instance’s cache,
- If not, then it checks the SQL Server Data Cache,
- And if not here then it fetches the data from the database.
The Business Central Server Instance’s Cache is accessible to all the Users connected to that Server Instance.
There are two types of cache stored here,
- Global Cache
- Private Cache
Global cache is the one which is accessible to all the Users connected to the SQL Server.
Private cache is only accessible over a transaction, for a particular User, for a particular company. This cache is cleared as soon as the transaction is completed.
Which cache is to be used for which User depends on whether the Table from which the User is requesting data is locked or not. In case it is locked, Private Cache is queried else Global Cache is queried.
The following procedures in Business Central support using Cache:
Whenever we make a call to the “FIND” functions, 1024 records are cached. The Data Cache size in Business Central can be changed using the “Data Cache Size” setting of the Business Central Server Configuration file. The default value is set to 9 which is equivalent to 500mb. Increasing the value by 1 doubles the cache size.
If we want to latest data from the database to be fetched, i.e. if we want to bypass the cache, we can use the “SelectLatestVersion” procedure.
The results from Query objects in Business Central are not cached.
If there are multiple Server Instances over a single database, Business Central synchronizes the cache every 30 seconds by default. We can change this by using the “CacheSynchronizationPeriod” parameter in the CustomSettings.config file.
Thus we saw how to Caching works in Business Central and how we can optimize it usage for maximum performance in Business Central.