Package io.sentry

Class HostnameCache

java.lang.Object
io.sentry.HostnameCache

@Internal public final class HostnameCache extends Object
Time sensitive cache in charge of keeping track of the hostname. The InetAddress.getLocalHost().getCanonicalHostName() call can be quite expensive and could be called for the creation of each SentryEvent. This system will prevent unnecessary costs by keeping track of the hostname for a period defined during the construction. For performance purposes, the operation of retrieving the hostname will automatically fail after a period of time defined by GET_HOSTNAME_TIMEOUT without result.

HostnameCache is a singleton and its instance should be obtained through getInstance().

  • Method Details

    • getInstance

      @NotNull public static @NotNull HostnameCache getInstance()
    • getHostname

      @Nullable public @Nullable String getHostname()
      Gets the hostname of the current machine.

      Gets the value from the cache if possible otherwise calls updateCache().

      Returns:
      the hostname of the current machine.