module ActionController::Caching::RedisPages::ClassMethods

Public Instance Methods

caches_redis_page(*actions) click to toggle source
# File lib/action_controller/caching/redis_pages.rb, line 16
def caches_redis_page(*actions)
  return unless (RedisPage.cache_relation_redis && RedisPage.cache_page_redis)
  options = actions.extract_options!

  before_filter({only: actions}.merge(options)) do |c|
    @page_need_to_cache = true
    if options[:append_country]
      # X-IP-Country 是通过 nginx GeoIP2 module 注入的 header
      @cache_country = (cookies[:country] || request.headers['X-IP-Country']).try(:upcase)
    end
  end

  after_filter({only: actions}.merge(options)) do |c|
    path = [request.path, @cache_country, RedisPage.compress_method].compact.join('-')
    c.cache_redis_page(compress_content(response.body), path, options)
    c.record_cached_page
  end
end