Class: HTTPX::Resolver::Cache::Base
- Inherits:
-
Object
- Object
- HTTPX::Resolver::Cache::Base
- Defined in:
- lib/httpx/resolver/cache/base.rb
Overview
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.
Direct Known Subclasses
Constant Summary collapse
- MAX_CACHE_SIZE =
512- CACHE_MUTEX =
Thread::Mutex.new
- HOSTS =
Resolv::Hosts.new
Class Attribute Summary collapse
-
.hosts_resolver ⇒ Object
readonly
Returns the value of attribute hosts_resolver.
Class Method Summary collapse
-
.cache(label) ⇒ Object
returns the singleton instance to be used within the current ractor.
Instance Method Summary collapse
-
#resolve(hostname) ⇒ Object
resolves
hostnameinto an instance of HTTPX::Resolver::Entry ifhostnameis an IP, or can be found in the cache, or can be found in the system hosts file.
Class Attribute Details
.hosts_resolver ⇒ Object (readonly)
Returns the value of attribute hosts_resolver.
20 21 22 |
# File 'lib/httpx/resolver/cache/base.rb', line 20 def hosts_resolver @hosts_resolver end |
Class Method Details
.cache(label) ⇒ Object
returns the singleton instance to be used within the current ractor.
23 24 25 26 27 28 29 |
# File 'lib/httpx/resolver/cache/base.rb', line 23 def cache(label) return Ractor.store_if_absent(:"httpx_resolver_cache_#{label}") { new } if Utils.in_ractor? @cache ||= CACHE_MUTEX.synchronize do @cache || new end end |
Instance Method Details
#resolve(hostname) ⇒ Object
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.
34 35 36 |
# File 'lib/httpx/resolver/cache/base.rb', line 34 def resolve(hostname) ip_resolve(hostname) || get(hostname) || hosts_resolve(hostname) end |