Class CachedEnvironment

java.lang.Object
io.micronaut.context.env.CachedEnvironment

@Internal public class CachedEnvironment extends Object
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 Details

    • CachedEnvironment

      public CachedEnvironment()
  • Method Details

    • getenv

      @Nullable public static @Nullable String getenv(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 to System.getenv(java.lang.String).
      Parameters:
      name - the name of the environment variable
      Returns:
      the value of the environment variable
    • getenv

      @NonNull public static @NonNull Map<String,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 to System.getenv(java.lang.String).
      Returns:
      the environment variables
    • getProperty

      @Nullable public static @Nullable String getProperty(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 to System.getProperty(String).
      Parameters:
      name - the name of the system property
      Returns:
      the value of the system property