Temporary Globals and the IRISTEMP Database
For some operations, you may need the power of globals without requiring the data to be saved indefinitely. For example, you may want to use a global to sort some data which you do not need to store to disk. For these operations, InterSystems IRIS provides the mechanism of temporary globals. This mechanism works as follows:
For your application namespace, you define a global mapping so that globals with a specific naming convention are to be mapped to the IRISTEMP database, which is a special database as discussed below.
For example, you might define a global mapping so that all globals with names of the form ^AcmeTemp* are mapped to the IRISTEMP database.
When your code needs to store data temporarily and read it again, your code writes to and reads from globals that use that naming convention.
For example, to save a value, your code might do this:
set ^AcmeTempOrderApp("sortedarray")=some valueCopy code to clipboard
Then later your code might do this:
set somevariable = ^AcmeTempOrderApp("sortedarray")Copy code to clipboard
By using temporary globals, you take advantage of the fact that the IRISTEMP database is not journaled. Because the database is not journaled, operations that use the database do not result in journal files. Journal files can become large and can cause space issues. However, note the following points:
You cannot roll back any transactions that modify globals in the IRISTEMP database; this behavior is specific to IRISTEMP. If you need to manage temporary work via transactions, do not use globals in IRISTEMP for that purpose.
Take care to use IRISTEMP only for work that does not need to be saved.
Defining a Mapping for Temporary Globals
To define a mapping for temporary globals, do the following:
Choose a naming convention and ensure that all of your developers are aware of it. Note the following points:
Consider whether to have many temporary globals or fewer temporary globals with multiple nodes. It is easier for InterSystems IRIS to efficiently read or write different nodes within the same global, compared to reading or writing the equivalent number of separate globals. The efficiency difference is negligible for small numbers of globals but is noticeable when there are hundreds of separate globals.
If you plan to use the same global mapping in multiple namespaces, then devise a system so that work in one namespace does not interfere with work in another namespace. For example, you could use the namespace name as a subscript in the globals.
Similarly, even within one namespace, devise a system so that each part of the code uses a different global or a different subscript in the same global, again to avoid interference.
Do not use system-reserved global names. See “Global Variable Names to Avoid” in the appendix “Rules and Guidelines for Identifiers” in Orientation Guide for Server-Side Programming.
In the Management Portal, navigate to the Namespaces page (System Administration > Configuration > System Configuration > Namespaces).
In the row for your application namespace, click Global Mappings.
From the Global Mappings page, click New Global Mapping .
For Global database location, select IRISTEMP.
For Global name, enter a name ending in an asterisk (*). Do not include the initial caret of the name.
For example: AcmeTemp*
This mapping causes all globals with names that start AcmeTemp* to be mapped to the IRISTEMP database.
Click OK .Note:
>> displayed in the first column of the new mappings row indicates that you opened the mapping for editing.
To save the mappings so that InterSystems IRIS uses them, click Save Changes.
For more details, see the chapter “Configuring InterSystems IRIS®” in the System Administration Guide.
System Use of IRISTEMP
Note that InterSystems uses temporary globals as scratch space, for example, as temporary indexes during the execution of certain queries (for sorting, grouping, calculating aggregates, etc.).
Some of the system globals contained in IRISTEMP are:
Never change any of these globals.