How Do I Fetch Data from a Database Table a Single Time for the Whole Application? (Magic xpa 3.x)
One of the more time-consuming activities for a program is reading data. If a table is accessed frequently, it will often speed up the application greatly if the table is read once and kept open. For read-only tables that are not updated frequently, it makes sense to read the entire table into memory and just access it as needed.
You needn’t do this manually, however. Within the Data Source Properties (Alt+Enter) for each data source is the Resident setting. If this is set to anything other than No, the data from the table is read into memory and stays there until the application closes. Such a table is called a Resident Table.
Resident tables are read-only. They are only fetched once, so it is assumed that these are used for data that doesn’t change frequently. However, if you do want to refresh them while the application is running, you can use the DbReload() function.
Note: Settings->Environment->Preferences->Load Resident Tables must be set to Yes, or the Resident setting will be ignored.
The Resident setting controls when the data is fetched into memory, as shown below.
No: This is the default setting. The table is not treated as a resident table. It closes as soon as the task that uses it closes.
Immediate: The table is loaded as soon as the application is loaded, and remains open until the application closes.
On Demand: The table is loaded the first time a program opens it, and remains open until the application closes.
Immediate and on Browser: The table is loaded directly from the browser and kept locally on the browser client side. The effect of a table set with this option, is that a recompute of a Link operation of that table is done locally.