Module: ActionController::Caching::Fragments

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

Constant Summary collapse

@@fragmented_locales =
[]

Instance Method Summary collapse

Instance Method Details

#expire_fragment_with_locale(name, options = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/locale_rails/action_controller/caching.rb', line 30

def expire_fragment_with_locale(name, options = nil)
  return unless perform_caching

  fc_store = (respond_to? :cache_store) ? cache_store : fragment_cache_store
  key = name.is_a?(Regexp) ? name : fragment_cache_key_without_locale(name)
  if key.is_a?(Regexp)
    self.class.benchmark "Expired fragments matching: #{key.source}" do
      fc_store.delete_matched(key, options)
    end
  else
    key = key.gsub(/:/, ".")
    self.class.benchmark "Expired fragment: #{key}, lang = #{@@fragmented_locales}" do
      @@fragmented_locales.each do |lang|
        fc_store.delete("#{key}_#{lang}", options)
      end
    end
  end
end

#fragment_cache_key_with_locale(name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/locale_rails/action_controller/caching.rb', line 17

def fragment_cache_key_with_locale(name) 
  ret = fragment_cache_key_without_locale(name)
  if ret.is_a? String
    unless @@fragmented_locales.include? I18n.locale
      @@fragmented_locales << I18n.locale
    end
    ret.gsub(/:/, ".") << "_#{I18n.locale}"
  else
    ret
  end
end