Using Caché Globals
Introduction
[Back] [Next]
   
Server:docs1
Instance:LATEST
User:UnknownUser
 
-
Go to:
Search:    

One of the central features of Caché is its multidimensional storage engine. This feature lets applications store data in compact, efficient, multidimensional sparse arrays. These arrays are referred to as globals.

This document describes:
Features
Globals provide an easy-to-use way to store data in persistent, multidimensional arrays.
For example, you can associate the value “Red” with the key “Color” using a global named Settings:
   SET ^Settings("Color")="Red"
   WRITE !,^Settings("Color")
 
You can take advantage of the multidimensional nature of globals to define a more complex structure:
^Settings("Auto1","Properties","Color") = "Red"
^Settings("Auto1","Properties","Model") = "SUV"
^Settings("Auto2","Owner") = "Mo"
^Settings("Auto2","Properties","Color") = "Green"
Globals have the following features:
Note:
The globals described in this document should not be confused with another type of Caché array variable: process-private globals. Process-private globals are not persistent; they persist only for the duration of the process that created them. Process-private globals are also not concurrent; they can only be accessed by the process that created them. A process-private global can be easily distinguished from a global by its multi-character name prefix: either ^|| or ^|"^"|.
Examples
A simple example can demonstrate the ease and performance of globals. The following program example creates a 10,000–node array (deleting it first if present) and stores it in the database. You can try this to get a sense of the performance of globals:
—Creating a Persistent Array—
 Set start = $ZH  // get current time

 Kill ^Test.Global
 For i = 1:1:10000 {
     Set ^Test.Global(i) = i
 }

 Set elap = $ZH - start  // get elapsed time
 Write "Time (seconds): ",elap
 
We can also see how long it takes to iterate over and read the values in the array (make sure to run the above example first to build the array):
—Reading a Persistent Array—
 Set start = $ZH  // get current time
 Set total = 0
 Set count = 0

 // get key and value for first node
 Set i = $Order(^Test.Global(""),1,data)

 While (i '= "") {
     Set count = count + 1
     Set total = total + data

    // get key and value for next node
    Set i = $Order(^Test.Global(i),1,data)
 }

 Set elap = $ZH - start  // get elapsed time

 Write "Nodes:          ",count,!
 Write "Total:          ",total,!
 Write "Time (seconds): ",elap,!
 
Use in Applications
Within Caché applications, globals are used in many ways, including:
Globals are not constrained by the confines of the relational model. They provide the freedom to develop customized structures optimized for specific applications. For many applications, judicious use of globals can be a secret weapon delivering performance that relational application developers can only dream about.
Whether your application makes direct use of globals or not, it is useful to understand their operation. Understanding globals and their capabilities will help you to design more efficient applications as well as provide help with determining the optimal deployment configuration for your applications.