Module: ActionController::Caching::Pages::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#caches_redis_page(*actions) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/action_controller/caching/pages.rb', line 13

def caches_redis_page(*actions)
  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']).upcase
    end
  end

  after_filter({only: actions}.merge(options)) do |c|
    path = request.path
    path = "#{path}-#{@cache_country}" if @cache_country
    c.cache_page(response.body, path)
    c.record_cached_page
  end
end