Class: HTTPX::Resolver::Cache::File

Inherits:
Base
  • Object
show all
Defined in:
lib/httpx/resolver/cache/file.rb

Overview

Implementation of a file resolver cache.

Constant Summary collapse

DEFAULT_PATH =

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.

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

Constants inherited from Base

Base::CACHE_MUTEX, Base::HOSTS, Base::MAX_CACHE_SIZE

Instance Method Summary collapse

Methods inherited from Base

cache, #resolve

Constructor Details

#initialize(path = DEFAULT_PATH) ⇒ File

Returns a new instance of File.



14
15
16
17
# File 'lib/httpx/resolver/cache/file.rb', line 14

def initialize(path = DEFAULT_PATH)
  super()
  @store = PStore.new(path, true)
end

Instance Method Details

#evict(hostname, ip) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/httpx/resolver/cache/file.rb', line 41

def evict(hostname, ip)
  ip = ip.to_s

  @store.transaction do
    lookups = @store[:lookups] || EMPTY_HASH
    hostnames = @store[:hostnames] || EMPTY

    _evict(hostname, ip, lookups, hostnames)

    @store[:lookups] = lookups
    @store[:hostnames] = hostnames
  end
end

#get(hostname) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/httpx/resolver/cache/file.rb', line 19

def get(hostname)
  now = Utils.now
  @store.transaction do
    lookups = @store[:lookups] || EMPTY_HASH
    hostnames = @store[:hostnames] || EMPTY

    _get(hostname, lookups, hostnames, now)
  end
end

#set(hostname, family, entries) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/httpx/resolver/cache/file.rb', line 29

def set(hostname, family, entries)
  @store.transaction do
    lookups = @store[:lookups] || {}
    hostnames = @store[:hostnames] || []

    _set(hostname, family, entries, lookups, hostnames)

    @store[:lookups] = lookups
    @store[:hostnames] = hostnames
  end
end