Sha256: 8f5cd5e09583c465f8679926fd5d63441414466f807d076d5fdfbeec2e3c8d45
Contents?: true
Size: 787 Bytes
Versions: 12
Compression:
Stored size: 787 Bytes
Contents
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, options={}) @fallback_backend.write(cache_key_for_fallback_backend(key), value, options) if @fallback_backend @cache[key] = value end def fetch(key, &block) read(key) || block.call.tap { |value| write(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
12 entries across 12 versions & 1 rubygems