diff --git a/lib/jekyll-include-cache/tag.rb b/lib/jekyll-include-cache/tag.rb index 73730ab..761faae 100644 --- a/lib/jekyll-include-cache/tag.rb +++ b/lib/jekyll-include-cache/tag.rb @@ -33,11 +33,32 @@ def path(context) def key(path, params) path_hash = path.hash - params_hash = params.hash + params_hash = quick_hash(params) self.class.digest_cache[path_hash] ||= {} self.class.digest_cache[path_hash][params_hash] ||= digest(path_hash, params_hash) end + def quick_hash(params) + return params.hash unless params + + md5 = Digest::MD5.new + + params.each do |key, value| + # Using the fact that Jekyll documents don't change within a site build. + # Instead of calculating the hash of an entire document (expesive!) + # we just use the object id. + # This allows posts and pages to be passed to `include_cached` + # without a performance penality. + if value.is_a? Jekyll::Drops::Drop + md5.update value.object_id.to_s + else + md5.update value.hash.to_s + end + end + + md5.hexdigest + end + def digest(path_hash, params_hash) md5 = Digest::MD5.new md5.update path_hash.to_s