Can a class refer to a global in a different namespace?
Some of our interfaces use globals for lookups, but we are currently looking at putting a groups of (document) interfaces in a separate production with a shared ‘Default Database for Routines’ to reduce code duplication.
We understand we could simply place these globals in the %SYS namespace so they can be accessed from all namespaces.
The manual seems to imply that using %SYS Namespace (CACHESYS database) to store globals is accepted practice, and establishes a strict naming convention to ensure globals are not overwritten.
Further down the same page (link below), 'percent globals' are introduced;
Any global whose name starts with a caret and a percent sign (
^% ). These globals are generally referred to aspercent globals . Note that via global mappings or subscript level mappings, it is possible to change where percent globals are stored, but that has no effect on their visibility. Percent globals are always visible in all namespaces.
Should we be using percent globals or %SYS/CACHESYS globals to store the global we want accessible between namespaces? Can I explicitly address a global in another namespace/database?
--
System-Supplied Namespaces
-
%SYS — This namespace provides access to code that should not be available in all namespaces — code that manipulates security elements, the server configuration, and so on.For this namespace, the default routine database and default global database isCACHESYS . If you follow certain naming conventions, you can create your own code and globals in this namespace and store it in that database. See the next section. -
DOCBOOK — The DocBook application uses this namespace.
-
Go to the
%SYS namespace and create the item. For this namespace, the default routine database and default global database are bothCACHESYS . Use the following naming conventions to prevent your items from being affected by the upgrade installation: -
In
any namespace, create items with the following names:Because of the standard mappings in any namespace, these items are written toCACHESYS .
Comments
Hi Stephen,
I would avoid using the system database CACHESYS to hold your application globals.
You should create another database that is specifically intended to hold the globals which would be common to all the productions you are running.
To enable the globals residing in this one, common database, to be visible from your various production namespaces - you would "map" these using Global Mapping rules defined against your production namespaces.
See the System Management Portal's Namespace configuration screens, and the Global Mappings feature, or look here:
Sincerely,
Steve
If you need to map the globals to multiple namespace, you can map them to the virtual namespace %ALL. (see this article: https://community.intersystems.com/post/defining-global-routine-and-pac…).
And yes, you can also explicitly reference globals from another namespace by using the syntax ^["other namespace"]myGlobal. (see in documentation: http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY…)
Hi!
I wouldn't recommend putting globals or routines on your %SYS namespace for two reasons:
- This will be shared with all namespaces. This may be what you want today, but may not be what you want in the future.
- One nice thing to organize your code, globals and classes on different databases is that you can simplify your patching procedures. Instead of shipping classes, globals and routines from DEV to TEST or LIVE you can ship the necessary databases. So, if you have a database for all your routines/classes/compiled_pages, and you have a new release of your application, you can copy the entire CODE database from DEV to TEST or LIVE and "upgrade" that environment. Of course upgrading an environment may involve other things like rebuilding some indices, running some patching code, etc. But again, you can backup your databases, move the new databases to replace the old ones, run your custom code and rebuild your indices (if necessary) and test it. If something fails, you can always revert back to the previous set of databases. Well, you can't do that if you have custom code and globals on %SYS since copying the CACHESYS database from one system to another is taking more than what you would like to take from that system to the other.
- With the new InterSystems Container Manager (ICM) that comes with InterSystems IRIS, there is this concept of "durable %SYS" where %SYS namespace is extracted from inside the container and put into an external volume. That is good because you can replace your container without loose all the system configurations you have stored on %SYS. But IRIS is not meant to be compatible with old practices such as taking care of your custom globals, routines and classes on %SYS. InterSystems may decide to change this behavior and make %SYS less custom code friendly.
So, you can perfectly create more databases to organize your libraries and globals and map them to your namespace without problems. One database for code tables, one database for some libraries you share between all your namespaces, one database for CODE another for DATA, etc. That is what namespaces are for: To rule them all.
Kind regards,
AS
- 'Should we be using percent globals or %SYS/CACHESYS globals to store the global we want accessible between namespaces? '
I will stay with a no answer (look at @Amir Samary">@Amir Samary comment).
- 'Can I explicitly address a global in another namespace/database?'
Well -----> Yes you can.
check this out: