Sha256: 779151d477cbbdf66bfad8fc2e1f06ea29648eca122c718f35b82304f1215065
Contents?: true
Size: 851 Bytes
Versions: 8
Compression:
Stored size: 851 Bytes
Contents
module RailsConnector class Cache attr_reader :cache_prefix 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 def clear @cache = {} end private def cache_key_for_fallback_backend(key) @cache_prefix ? "#{@cache_prefix}/#{key}" : key end end end # module RailsConnector
Version data entries
8 entries across 8 versions & 1 rubygems