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::Resolver->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, no_cache => $boolean, debug => $mode)

Resolve a domain.

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

Additionally, named arguments can be specified.

The no_cache argument specifies whether any previously cached result should be ignored or not. Note that, even when no_cache option is specified, the result of this resolution will be cached.

The debug argument specifies 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-2017 Wakaba <wakaba@suikawiki.org>.

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