Class: Mihari::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/mihari/cache.rb

Constant Summary collapse

DEFAULT_CACHE_DIR =
"/tmp/mihari"

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



9
10
11
# File 'lib/mihari/cache.rb', line 9

def initialize
  @data = Lightly.new(life: "7d", dir: DEFAULT_CACHE_DIR)
end

Instance Method Details

#cached?(key) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
# File 'lib/mihari/cache.rb', line 13

def cached?(key)
  return false unless @data.enabled?

  begin
    @data.cached? key
  rescue Errno::ENOENT => _e
    false
  end
end

#save(*keys) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mihari/cache.rb', line 23

def save(*keys)
  return unless @data.enabled?

  begin
    keys.flatten.each do |key|
      @data.save key, true
    end
  rescue Errno::ENOENT => _e
    nil
  end
end