Class: HTTPX::Resolver::Cache::Memory
- Defined in:
- lib/httpx/resolver/cache/memory.rb
Overview
Implementation of a thread-safe in-memory LRU resolver cache.
Constant Summary
Constants inherited from Base
Base::CACHE_MUTEX, Base::HOSTS, Base::MAX_CACHE_SIZE
Instance Method Summary collapse
- #evict(hostname, ip) ⇒ Object
- #get(hostname) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #set(hostname, family, entries) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
7 8 9 10 11 12 |
# File 'lib/httpx/resolver/cache/memory.rb', line 7 def initialize super @hostnames = [] @lookups = Hash.new { |h, k| h[k] = [] } @lookup_mutex = Thread::Mutex.new end |
Instance Method Details
#evict(hostname, ip) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/httpx/resolver/cache/memory.rb', line 27 def evict(hostname, ip) ip = ip.to_s synchronize do |lookups, hostnames| _evict(hostname, ip, lookups, hostnames) end end |
#get(hostname) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/httpx/resolver/cache/memory.rb', line 14 def get(hostname) now = Utils.now synchronize do |lookups, hostnames| _get(hostname, lookups, hostnames, now) end end |
#set(hostname, family, entries) ⇒ Object
21 22 23 24 25 |
# File 'lib/httpx/resolver/cache/memory.rb', line 21 def set(hostname, family, entries) synchronize do |lookups, hostnames| _set(hostname, family, entries, lookups, hostnames) end end |