Sha256: e56988cb4b30528a1fc13f8307f3601787cc0b39487d34a9f9d36fb966854b98

Contents?: true

Size: 682 Bytes

Versions: 5

Compression:

Stored size: 682 Bytes

Contents

#:enddoc:
module RailsConnector

class Cache
  def initialize(options = {})
    @fallback_backend, @cache_prefix = options[:fallback_backend], options[:cache_prefix]
    @cache = {}
  end

  def read(key)
    value = @cache[key]
    if !value && @fallback_backend
      value = @fallback_backend.read(cache_key_for_fallback_backend(key))
      @cache[key] = value
    end
    value
  end

  def write(key, value)
    @fallback_backend.write(cache_key_for_fallback_backend(key), value) if @fallback_backend
    @cache[key] = value
  end

  private

  def cache_key_for_fallback_backend(key)
    @cache_prefix ? "#{@cache_prefix}/#{key}" : key
  end
end

end # module RailsConnector

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.8.0.beta.200.883.f5f063b lib/rails_connector/cache.rb
infopark_cloud_connector-6.8.0.beta.200.884.4bd86e6 lib/rails_connector/cache.rb
infopark_cloud_connector-6.8.0.beta.200.869.9609b39 lib/rails_connector/cache.rb
infopark_cloud_connector-6.8.0.beta.200.856.8c0fec5 lib/rails_connector/cache.rb
infopark_cloud_connector-6.8.0.beta.200.809.bdfa8c3 lib/rails_connector/cache.rb