8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/kaminari-cache.rb', line 8
def
store_class = Rails.cache.class.name.split("::").last
if Rails.cache.respond_to? "delete_matched"
self.changed.each do |field|
match = [:kaminari, "/#{self.class.name.downcase}", '*', "/#{:order}", '*', "/#{field}", '*']
Rails.logger.info "Cache flush: #{match.join}"
case store_class
when "DalliStore"
regexp = Regexp.new match.join.gsub(/\*/,'.*?')
Rails.cache.delete_matched /^#{Regexp.escape(:kaminari)}\/#{Regexp.escape(self.class.name.downcase)}/
when "RedisStore"
Rails.cache.delete_matched match.join
end
end
else
Rails.cache.clear
Rails.logger.warn "#{store_class} does not support deleting matched keys. The entire cache was flushed. Consider using RedisStore (Redis) OR DalliStore (gem dalli) for memcached with dalli-store-extensions gem for improved performance."
end
end
|