class HTTPX::Resolver::Cache::File

  1. lib/httpx/resolver/cache/file.rb
Superclass: Base

Implementation of a file resolver cache.

Methods

Public Class

  1. new

Public Instance

  1. evict
  2. get
  3. set

Constants

DEFAULT_PATH = ::File.join(Dir.tmpdir, "httpx-ruby-#{VERSION}.cache")  

default path where the resolver cache is stored. It’s versioned, as the file may change format in-between releases, and it’d signal it as corrupted.

Public Class methods

new(path = DEFAULT_PATH)
[show source]
   # File lib/httpx/resolver/cache/file.rb
14 def initialize(path = DEFAULT_PATH)
15   super()
16   @store = PStore.new(path, true)
17 end

Public Instance methods

evict(hostname, ip)
[show source]
   # File lib/httpx/resolver/cache/file.rb
41 def evict(hostname, ip)
42   ip = ip.to_s
43 
44   @store.transaction do
45     lookups = @store[:lookups] || EMPTY_HASH
46     hostnames = @store[:hostnames] || EMPTY
47 
48     _evict(hostname, ip, lookups, hostnames)
49 
50     @store[:lookups] = lookups
51     @store[:hostnames] = hostnames
52   end
53 end
get(hostname)
[show source]
   # File lib/httpx/resolver/cache/file.rb
19 def get(hostname)
20   now = Utils.now
21   @store.transaction do
22     lookups = @store[:lookups] || EMPTY_HASH
23     hostnames = @store[:hostnames] || EMPTY
24 
25     _get(hostname, lookups, hostnames, now)
26   end
27 end
set(hostname, family, entries)
[show source]
   # File lib/httpx/resolver/cache/file.rb
29 def set(hostname, family, entries)
30   @store.transaction do
31     lookups = @store[:lookups] || {}
32     hostnames = @store[:hostnames] || []
33 
34     _set(hostname, family, entries, lookups, hostnames)
35 
36     @store[:lookups] = lookups
37     @store[:hostnames] = hostnames
38   end
39 end