Module: KaminariCache
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/kaminari-cache.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/kaminari-cache.rb', line 4 def self.included(base) base.after_update :flush_pagination_cache end |
Instance Method Details
#flush_match(match) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kaminari-cache.rb', line 24 def flush_match(match) Rails.logger.info "Cache flush: #{match.join}" case @store_class when "DalliStore" # DalliStore uses a Regexp regexp = Regexp.new match.join.gsub(/\*/,'.*?') Rails.cache.delete_matched /^#{Regexp.escape(:kaminari)}\/#{Regexp.escape(self.class.name.downcase)}/ when "RedisStore" # RedisStore uses a String Rails.cache.delete_matched match.join end end |
#flush_pagination_cache ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kaminari-cache.rb', line 8 def flush_pagination_cache @store_class = Rails.cache.class.name.split("::").last if Rails.cache.respond_to? "delete_matched" self.changed.each do |field| flush_match [:kaminari, "/#{self.class.name.downcase}", '*', "/#{:order}", '*', "/#{field}", '*'] end # flush scoped pagings... flush_match [:kaminari, "/#{self.class.name.downcase}", '*', "/#{:scope}", '*'] 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 |