Appendix: Data Source Cache

When a data source connects to the underlying data, this is known as making a Data Source Call. Every time a call is made, the resulting data is stored in the current session memory. Each set of stored data is known as a Cached Item, and they are collectively known as the Cache. Each item is named according to how the data was called, which means that if the call is made using a data source filter, the cached item will be named after that filter. If the data is not filtered, the cached item will be named after the data source itself.

The following table shows an example of how this works, based on a model that uses five calls across two separate data sources, resulting in five distinct cached items:

Data Source Name Data Source Filter Cached Item Name Explanation
Customers n/a Customers Because the call returned unfiltered data, the cached item is named after the data source.
Customers OldEntries OldEntries Although the call uses the same data source as the previous one, it also uses a filter, so the cached item is named after that filter.
Orders n/a Orders The call uses a different data source to the previous call, but again has no filter, so the cached item is named after the data source.
Companies NewEntries NewEntries Again, the call uses a filter, so the cached item inherits that filter's name.
Companies OldEntries OldEntries Like the previous one, this cached item is named after the filter, even though another cached item - from a different data source - has the same name.

Despite the second and fifth items in the above example having the same name, each one is distinguishable by the name of its data source, and so they can both exist at the same time. To delete a cached item using the DataSourceCache function, you need to specify the data source name in addition to the cached item name.

All model content that makes use of a particular combination of data source and filter will use the data in the corresponding cached item, rather than making a new call each time. Cached data will not change until the data source is refreshed, at which point a new call is made and the cached item is updated with the latest data.

By default, cached items will remain in memory until the session ends. This can have an impact on performance if your application makes multiple calls or retrieves large amounts of data in a single session.

For example, you might want to use a data source to populate the response list of a Multiple Choice question. When the user has selected their response and moved on to the next step of the application, the associated data will remain cached in session memory, even though it may no longer be needed.

It is important to anticipate when cached items will no longer be needed, and use the following functions to avoid performance issues:

  • ListDataSourceCache - Returns a list of all current cached items, optionally including the row count and size of each item, and the total size of the cache.
  • DataSourceCache - Deletes all or part of the current cache.

You can learn how to use these functions by referring to the Data Source Functions mini-guide, which is available on the KnowledgeKube Training Academy website here.