Sha256: f36da6df0034f625d65731cc3873487b4f3a5fe01a8eefd45574cbbc4e55061d

Contents?: true

Size: 778 Bytes

Versions: 3

Compression:

Stored size: 778 Bytes

Contents

module ECB
  module Exchange
    class Cache
      KEY_PREFIX = "ecb_exchange_rates_for_date".freeze

      class << self
        attr_accessor :backend
      end

      def self.write(key, value)
        store.write(cache_key(key), value)
      end

      def self.read(key)
        store.read(cache_key(key))
      end

      # use backend if set (must respond to read, write), otherwise Rails.cache
      # will be used (if available) or we fall back to use an in-memory cache
      def self.store
        if backend
          backend
        elsif defined?(Rails) && Rails.cache
          Rails.cache
        else
          MemoryCache.cache
        end
      end

      private
        def self.cache_key(key)
          "#{KEY_PREFIX}-#{key}"
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ecb_exchange-0.1.2 lib/ecb/exchange/cache.rb
ecb_exchange-0.1.1 lib/ecb/exchange/cache.rb
ecb_exchange-0.1.0 lib/ecb/exchange/cache.rb