class HTTPX::Resolver::Cache::Base

  1. lib/httpx/resolver/cache/base.rb
Superclass: Object

Base class of the Resolver Cache adapter implementations.

While resolver caches are not required to inherit from this class, it nevertheless provides common useful functions for desired functionality, such as singleton object ractor-safe access, or a default resolve implementation which deals with IPs and the system hosts file.

Methods

Public Class

  1. cache
  2. hosts_resolver

Public Instance

  1. resolve

Constants

CACHE_MUTEX = Thread::Mutex.new  
HOSTS = Resolv::Hosts.new  
MAX_CACHE_SIZE = 512  

Attributes

Public Class methods

cache(label)

returns the singleton instance to be used within the current ractor.

[show source]
   # File lib/httpx/resolver/cache/base.rb
23 def cache(label)
24   return Ractor.store_if_absent(:"httpx_resolver_cache_#{label}") { new } if Utils.in_ractor?
25 
26   @cache ||= CACHE_MUTEX.synchronize do
27     @cache || new
28   end
29 end

Public Instance methods

resolve(hostname)

resolves hostname into an instance of HTTPX::Resolver::Entry if hostname is an IP, or can be found in the cache, or can be found in the system hosts file.

[show source]
   # File lib/httpx/resolver/cache/base.rb
34 def resolve(hostname)
35   ip_resolve(hostname) || get(hostname) || hosts_resolve(hostname)
36 end