Skip to main content

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® data platform provides the mechanism of temporary globals.

Temporary globals have the following characteristics:

  • Temporary globals are stored within the IRISTEMP database, which is always defined to be a local (that is, a non-network) database. All globals mapped to the IRISTEMP database are treated as temporary globals.

  • Changes to temporary globals are not written to disk. Instead the changes are maintained within the in-memory buffer pool. A large temporary global may be written to disk if there is not sufficient space for it within the buffer pool.

  • For maximum efficiency, changes to temporary globals are not logged to a journal file.

  • Temporary globals are automatically deleted whenever InterSystems IRIS is restarted. (Note: it can be a very long time before a live system is restarted; so you should not count on this for cleaning up temporary globals.)

Tip:

Temporary globals are useful when you need temporary data for use by multiple processes. If you need temporary data for use only within a single process, consider using a process-private global, which is a special form of variable that is available only within the process that creates it and that is automatically removed when the process ends.

Using Temporary Globals

The mechanism for using temporary globals 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 value
    

    Then later your code might do this:

     set somevariable = ^AcmeTempOrderApp("sortedarray")
    

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.

  • The IRISTEMP database increases in size when it requires more memory. You can use the MaxIRISTempSizeAtStart parameter to help manage the size of IRISTEMP.

Defining a Mapping for Temporary Globals

To define a mapping for temporary globals, do the following:

  1. 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.

  2. In the Management Portal, navigate to the Namespaces page (System Administration > Configuration > System Configuration > Namespaces).

  3. In the row for your application namespace, click Global Mappings.

  4. From the Global Mappings page, click New Global Mapping .

  5. For Global database location, select IRISTEMP.

  6. 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.

  7. Click OK.

    Note:

    The >> symbol displayed in the first column of the new mappings row indicates that you opened the mapping for editing.

  8. To save the mappings so that InterSystems IRIS uses them, click Save Changes.

For more details, see Configuring Namespaces.

System Use of IRISTEMP

Note that InterSystems uses temporary system globals as scratch space, for example, as temporary indexes during the execution of certain queries (for sorting, grouping, calculating aggregates, etc.). These globals are automatically mapped to IRISTEMP and include:

  • ^IRIS.Temp*

  • ^CacheTemp*

  • ^mtemp*

Never change any of these globals.

^CacheTemp Globals

Historically, customers have used globals having names starting with ^CacheTemp as temporary globals. By convention, these globals use names starting with ^CacheTempUser to avoid possible conflict with temporary system globals. However, the best practice is to define your own temporary globals and map them to IRISTEMP, as described in Using Temporary Globals.

FeedbackOpens in a new tab