Package io.micronaut.context.env
Class CachedEnvironment
java.lang.Object
io.micronaut.context.env.CachedEnvironment
A "cached environment" is a performance optimization aimed at minimizing
the cost of calling
System.getenv()
or System.getProperties()
.
The API is therefore a mirror to the equivalent System
class calls,
except that if "environment caching" is enabled, then all system properties
and all environment variables are deemed immutable: they will be queried at
application startup once and cached forever.
By default, caching is disabled. Should you want to have caching enabled,
you must make sure that a call to StaticOptimizations.cacheEnvironment()
is made prior to initializing this class.- Since:
- 3.2.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetenv()
Returns the complete set of environment variables.Returns the value of the requested environment variable.getProperty
(String name) Returns the system property of the requested name.
-
Constructor Details
-
CachedEnvironment
public CachedEnvironment()
-
-
Method Details
-
getenv
Returns the value of the requested environment variable. If caching is enabled, the value will be the one computed at startup time: changes won't be visible. If caching is not enabled, this just delegates toSystem.getenv(java.lang.String)
.- Parameters:
name
- the name of the environment variable- Returns:
- the value of the environment variable
-
getenv
Returns the complete set of environment variables. If caching is enabled, the value will be the one computed at startup time: changes won't be visible. If caching is not enabled, this just delegates toSystem.getenv(java.lang.String)
.- Returns:
- the environment variables
-
getProperty
Returns the system property of the requested name. If caching is enabled, the value will be the one computed at startup time: changes won't be visible. If caching is not enabled, this just delegates toSystem.getProperty(String)
.- Parameters:
name
- the name of the system property- Returns:
- the value of the system property
-