The manakai project

Web::Transport::CachedResolver

Resolve domain names, with caching

SYNOPSIS

  use Web::Transport::PlatformResolver;
  use Web::Transport::CachedResolver;
  use Web::DateTime::Clock;
  $resolver = Web::Transport::CachedResolver->new_from_resolver
      (Web::Transport::PlatformResolver->new,
       Web::DateTime::Clock->monotonic_clock);
  $resolver->resolve (Web::Host->parse_string ("example.com"))->then (sub {
    warn defined $_[0] && $_[0]->stringify;
  });

DESCRIPTION

The Web::Transport::CachedResolver module defines a name resolver which has a 60-seconds cache.

This module is a resolver (see "RESOLVERS" in Web::Transport).

METHOD

Following methods are available:

$resolver = Web::Transport::CachedResolver->new_from_resolver_and_clock ($resolver, $clock)

Create a resolver.

The first argument must be a "real" resolver. It must implement the resolve method which is compatible with Web::Transport::PlatformResolver's resolve.

The second argument must be a monotonic clock, e.g. Web::DateTime::Clock->monotonic_clock.

$promise = $resolver->resolve ($host, $name => $value, ...)

Resolve a domain.

The first argument must be a host (Web::Host) to resolve.

Additionally, following named arguments can be specified:

no_cache => $boolean

Whether any previously cached result should be ignored or not. The value is a boolean. Note that, even when no_cache option is specified, the result of this resolution will be cached.

signal => $signal

The abort signal (AbortSignal) for the resolution. If the abort controller (AbortController) associated with the signal is aborted, the resolution is aborted and the method's promise is rejected with an object whose name is AbortError whenever possible.

debug => $debug

The debug mode. The default value is 0 (not in the debug mode). See WEBUA_DEBUG section in Web::Transport for available mode values.

The method returns a promise (Promise), which is to be resolved with the result. If the host is a domain and is successfully resolved into an IP address, or the host is an IP address, the promise is resolved with a host (Web::Host) representing that IP address. Otherwise, it is resolved with undef.

SEE ALSO

Web::Transport::PlatformResolver.

SPECIFICATION

Web Transport Processing <https://wiki.suikawiki.org/n/Web%20Transport%20Processing>.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2016-2019 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.