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.
Constants
| CACHE_MUTEX | = | Thread::Mutex.new | ||
| HOSTS | = | Resolv::Hosts.new | ||
| MAX_CACHE_SIZE | = | 512 |
Attributes
| hosts_resolver | [R] |
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