Module: ActionController::Caching::RedisPages::ClassMethods

Defined in:
lib/action_controller/caching/redis_pages.rb

Instance Method Summary collapse

Instance Method Details

#caches_redis_page(*actions) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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