mirror of
https://github.com/jekyll/jekyll.git
synced 2026-04-28 03:01:03 -04:00
Compare commits
3 Commits
v3.1.3
...
cache-incl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c5399b947 | ||
|
|
0d6064b1a1 | ||
|
|
32ff033f9f |
1
Gemfile
1
Gemfile
@@ -23,6 +23,7 @@ gem 'minitest' if RUBY_PLATFORM =~ /cygwin/
|
||||
gem 'test-unit' if RUBY_PLATFORM =~ /cygwin/ || RUBY_VERSION.start_with?("2.2")
|
||||
|
||||
if ENV['BENCHMARK']
|
||||
gem 'benchmark-ips'
|
||||
gem 'rbtrace'
|
||||
gem 'stackprof'
|
||||
end
|
||||
|
||||
32
benchmark/cached-includes.rb
Normal file
32
benchmark/cached-includes.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
require 'benchmark/ips'
|
||||
require 'jekyll'
|
||||
|
||||
site = Jekyll::Site.new(Jekyll.configuration({
|
||||
'source' => File.expand_path('../site', __dir__),
|
||||
'destination' => File.expand_path('../site/_site', __dir__)
|
||||
}))
|
||||
payload = Jekyll::Utils.deep_merge_hashes(
|
||||
site.site_payload,
|
||||
{ 'site' => {'page' => site.pages.first.to_liquid } }
|
||||
)
|
||||
info = {
|
||||
filters: [Jekyll::Filters],
|
||||
registers: { :site => site, :page => payload['page'] }
|
||||
}
|
||||
|
||||
class WithoutCacheInclude < Jekyll::Tags::IncludeTag
|
||||
def source(file, context)
|
||||
File.read(file, file_read_opts(context))
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('include_woc', WithoutCacheInclude)
|
||||
|
||||
def parse(tag, payload, info)
|
||||
Liquid::Template.parse("{% #{tag} footer.html %}").render!(payload, info)
|
||||
end
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('cached') { parse 'include', payload, info }
|
||||
x.report('uncached') { parse 'include_woc', payload, info }
|
||||
end
|
||||
@@ -18,6 +18,12 @@ module Jekyll
|
||||
VALID_SYNTAX = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
|
||||
VARIABLE_SYNTAX = /(?<variable>[^{]*\{\{\s*(?<name>[\w\-\.]+)\s*(\|.*)?\}\}[^\s}]*)(?<params>.*)/
|
||||
|
||||
class << self
|
||||
def source_cache
|
||||
@@source_cache ||= {}
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(tag_name, markup, tokens)
|
||||
super
|
||||
@includes_dir = tag_includes_dir
|
||||
@@ -156,7 +162,7 @@ eos
|
||||
|
||||
# This method allows to modify the file content by inheriting from the class.
|
||||
def source(file, context)
|
||||
File.read(file, file_read_opts(context))
|
||||
self.class.source_cache[file] ||= File.read(file, file_read_opts(context))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user