lib/cache_flow.rb in laserlemon-cache_flow-0.1.3 vs lib/cache_flow.rb in laserlemon-cache_flow-0.1.4

- old
+ new

@@ -87,11 +87,27 @@ def json_cache_key(options) serialization_cache_key(:json, options.merge(:include_root_in_json => include_root_in_json)) end def serialization_cache_key(extension, options) - query = options.except(:cache).reject{|k,v| v.nil? }.to_query - ["#{cache_key}.#{extension}", query].delete_if(&:blank?).join('?') + query = options.except(:cache, :skip_instruct).reject{|k,v| v.nil? }.to_query + key = ["#{cache_key}.#{extension}", query].delete_if(&:blank?).join('?') + if cache_key_limit && (key.size > cache_key_limit) + "#{cache_key}.#{extension}?#{hashed_serialization_query(query)}" + else + key + end + end + + def cache_key_limit + case Rails.cache.class.name.demodulize.underscore.to_sym + when :mem_cache_store then 250 + end + end + + def hashed_serialization_query(query) + require 'digest/sha1' unless defined?(Digest) && defined?(Digest::SHA1) + "cache_flow=#{Digest::SHA1.hexdigest(query)}" end end end end