Skip to content
This repository
Nathan Esquenazi
file 25 lines (22 sloc) 0.727 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# 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

  end
end
Something went wrong with that request. Please try again.