Inspecting the caching mechanism
Caching is a technique that's used to store frequently used data in memory so that, when the same data is needed again, it can be retrieved from memory, thus saving time and improving the performance of the component. Let's look at the caching mechanism provided by the framework.
The Power Apps component framework provides a third parameter in the init method, called state, that saves the states of objects in a single session for a user. So, let's see how we can utilize the state to persist the data in the code component.
Saving the state in the code component is very straightforward. The framework provides a method called context.mode.setControlState, which takes in one parameter of the Dictionary type. This is provided by the framework. Before we start, we are going to follow a strategy similar to the one we used in Chapter 5, Code, Test, and Repeat, where we initialized some of the properties at a class level because they were...