Sha256: b7f30aee8f31396080c254715cb46a6c65b2f5395074ed190efc872f577a7938

Contents?: true

Size: 593 Bytes

Versions: 19

Compression:

Stored size: 593 Bytes

Contents

# frozen_string_literal: true

require "lightly"

module Mihari
  class Cache
    DEFAULT_CACHE_DIR = "/tmp/mihari"

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

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

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

    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
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
mihari-0.17.5 lib/mihari/cache.rb
mihari-0.17.4 lib/mihari/cache.rb
mihari-0.17.3 lib/mihari/cache.rb
mihari-0.17.2 lib/mihari/cache.rb
mihari-0.17.1 lib/mihari/cache.rb
mihari-0.17.0 lib/mihari/cache.rb
mihari-0.16.0 lib/mihari/cache.rb
mihari-0.15.0 lib/mihari/cache.rb
mihari-0.14.0 lib/mihari/cache.rb
mihari-0.13.2 lib/mihari/cache.rb
mihari-0.13.1 lib/mihari/cache.rb
mihari-0.13.0 lib/mihari/cache.rb
mihari-0.12.0 lib/mihari/cache.rb
mihari-0.11.0 lib/mihari/cache.rb
mihari-0.10.0 lib/mihari/cache.rb
mihari-0.9.1 lib/mihari/cache.rb
mihari-0.9.0 lib/mihari/cache.rb
mihari-0.8.2 lib/mihari/cache.rb
mihari-0.8.1 lib/mihari/cache.rb