lib/cache_flow.rb in laserlemon-cache_flow-0.1.0 vs lib/cache_flow.rb in laserlemon-cache_flow-0.1.1
- old
+ new
@@ -45,26 +45,28 @@
private
def with_cache_flow(extension, options, &block)
if options.has_key?(:cache) ? options.delete(:cache) : self.class.cache_serialization
options.merge!(:cache => false)
- key = send("#{extension}_cache_key", options)
- Rails.cache.fetch(key){ yield }
+ key, value = send("#{extension}_cache_key", options), yield
+ Rails.cache.fetch(key){ value.respond_to?(:dup) ? value.dup : value }
else
yield
end
end
def xml_cache_key(options)
- serialized_cache_key(:xml, options.except(:builder))
+ level = options.has_key?(:builder) ? options[:builder].instance_eval{ @level } : nil
+ serialized_cache_key(:xml, options.except(:builder).merge(:level => level))
end
def json_cache_key(options)
serialized_cache_key(:json, options)
end
def serialized_cache_key(extension, options)
- ["#{cache_key}.#{extension}", options.except(:cache).to_query].delete_if(&:blank?).join('?')
+ query = options.except(:cache).reject{|k,v| v.nil? }.to_query
+ ["#{cache_key}.#{extension}", query].delete_if(&:blank?).join('?')
end
end
end
end