Sha256: 6abb2b69ace046cc321d38f763b56fc7fa0bceb1ce74fd630d3724411fbaa9cf

Contents?: true

Size: 1.06 KB

Versions: 14

Compression:

Stored size: 1.06 KB

Contents

# Defines the default cache engine for RABL when caching is invoked for a template.
# You can define your own caching engines by creating an object that responds to fetch and
# setting the configuration option:
#
#     config.cache_engine = AdvancedCacheEngine.new
#

module Rabl
  class CacheEngine

    # Fetch given a key and options and a fallback block attempts to find the key in the cache
    # and stores the block result in there if no key is found.
    #
    # cache = Rabl::CacheEngine.new; cache.fetch("some_key") { "fallback data" }
    #
    def fetch(key, cache_options, &block)
      if defined?(Rails)
        Rails.cache.fetch(key, cache_options, &block)
      else
        yield
      end
    end

    def write(key, value, options = {})
      if defined?(Rails)
        Rails.cache.write(key, value, options)
      end
    end

    def read_multi(*keys)
      options = keys.extract_options!
      if defined?(Rails)
        Rails.cache.read_multi(*keys, options)
      else
        keys.inject({}) { |hash, key| hash[key] = nil; hash }
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
rabl-0.14.0 lib/rabl/cache_engine.rb
rabl-0.13.1 lib/rabl/cache_engine.rb
rabl-0.13.0 lib/rabl/cache_engine.rb
rabl-0.12.0 lib/rabl/cache_engine.rb
rabl-0.11.8 lib/rabl/cache_engine.rb
rabl-0.11.7 lib/rabl/cache_engine.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/rabl-0.11.6/lib/rabl/cache_engine.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/rabl-0.11.6/lib/rabl/cache_engine.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rabl-0.11.6/lib/rabl/cache_engine.rb
rabl-0.11.6 lib/rabl/cache_engine.rb
rabl-0.11.5 lib/rabl/cache_engine.rb
rabl-0.11.4 lib/rabl/cache_engine.rb
rabl-0.11.3 lib/rabl/cache_engine.rb
rabl-0.11.2 lib/rabl/cache_engine.rb