To better understand how AsyncDataModel uses caching to interact with a ListView, here are a few diagrams that show how the cache loads and updates data, assuming a cache size of 200 (the default capacity) and the use of overall revisions. As a user scrolls through a list, the list must continually update itself using data from the cache.
Initial cache load
The cache loads the first 200 items from the data source when load() is called. The cache now contains items 0 to 199.
Request near the end of the cache
A cache move occurs when the ListView requests data near the end of the cache, for example, around 20% from the edge (item 160 in this example). The AsyncDataModel retrieves the next 60 items from the data source to center the cache at item 160. The cache now contains items 60 to 259 and this is enough data for the ListView to update without the user noticing. The AsyncDataModel reports this change to the ListView.
Change in the data source
A cache refresh occurs when the source data changes. The dataChanged() signal is emitted and AsyncDataModel retrieves the 200 items that are above and overlapping the current cache position, including items that may be currently visible in the ListView. This ensures the cache and the ListView contain the most recent information when the user scrolls up or down. The AsyncDataModel reports this change to the ListView.
Request for items not in the cache
A cache miss occurs when the ListView requests items that aren't in the cache (in this example, a request for item 260 causes a cache miss). This could be due to the user scrolling rapidly through the list. When this happens, AsyncDataModel retrieves the next 100 items to center the cache at item 260. The cache now contains items 160 to 359. The AsyncDataModel reports this change to the ListView.
When the query request to retrieve data from the data source is started, any intermediate queries are discarded.
If you're not using revisions or keys, updates due to a cache move, refresh, or miss may cause significant disruption in the ListView display.