Package io.micronaut.context.env
Class CachedEnvironment
- java.lang.Object
-
- io.micronaut.context.env.CachedEnvironment
-
@Internal public class CachedEnvironment extends java.lang.Object
A "cached environment" is a performance optimization aimed at minimizing the cost of callingSystem.getenv()
orSystem.getProperties()
. The API is therefore a mirror to the equivalentSystem
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 toStaticOptimizations.cacheEnvironment()
is made prior to initializing this class.- Since:
- 3.2.0
-
-
Constructor Summary
Constructors Constructor Description CachedEnvironment()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Map<java.lang.String,java.lang.String>
getenv()
Returns the complete set of environment variables.static java.lang.String
getenv(java.lang.String name)
Returns the value of the requested environment variable.static java.lang.String
getProperty(java.lang.String name)
Returns the system property of the requested name.
-
-
-
Method Detail
-
getenv
@Nullable public static java.lang.String getenv(java.lang.String name)
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
@NonNull public static java.util.Map<java.lang.String,java.lang.String> 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
@Nullable public static java.lang.String getProperty(java.lang.String name)
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
-
-