Sha256: 7386f9f36afaaa8694f8d7e7986bcc663862356f33af30559067c710f759f4df

Contents?: true

Size: 482 Bytes

Versions: 2

Compression:

Stored size: 482 Bytes

Contents

module Economy
  class Cache

    def get(from, to)
      client.get "exchanges/#{from.iso_code.downcase}/#{to.iso_code.downcase}"
    end

    def set(exchange)
      client.set "exchanges/#{exchange.from.downcase}/#{exchange.to.downcase}", exchange.rate.to_s
    end

    def clear
      client.del 'exchanges/*'
    end

    private

    def client
      @client ||= begin
        require 'redis'
        Redis.new url: Rails.configuration.redis_url
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
economy-4.0.0.0 lib/economy/cache.rb
economy-0.0.1 lib/economy/cache.rb