Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure cache_dir #7232

Merged
merged 1 commit into from Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions features/cache.feature
@@ -0,0 +1,28 @@
Feature: Cache
As a developer who likes to create plugins
I want to be able to cache certain aspects across multiple builds
And retrieve the cached aspects when needed

Scenario: Default Cache directory
Given I have an "index.md" page that contains "{{ site.title }}"
And I have a configuration file with "title" set to "Hello World"
When I run jekyll build
Then I should get a zero exit status
And the .jekyll-cache directory should exist
And the .jekyll-cache/Jekyll/Cache/Jekyll--Cache directory should exist
And the _site directory should exist
And I should see "<p>Hello World</p>" in "_site/index.html"

Scenario: Custom Cache directory
Given I have an "index.md" page that contains "{{ site.title }}"
And I have a configuration file with:
| key | value |
| title | Hello World |
| cache_dir | .foo-cache |
When I run jekyll build
Then I should get a zero exit status
And the .foo-cache directory should exist
And the .foo-cache/Jekyll/Cache/Jekyll--Cache directory should exist
But the .jekyll-cache directory should not exist
And the _site directory should exist
And I should see "<p>Hello World</p>" in "_site/index.html"
6 changes: 5 additions & 1 deletion lib/jekyll/cache.rb
Expand Up @@ -14,11 +14,15 @@ class Cache
#
# Returns nothing.
def initialize(name)
@@base_dir ||= File.expand_path(".jekyll-cache/Jekyll/Cache")
@cache = @@caches[name] ||= {}
@name = name.gsub(%r![^\w\s-]!, "-")
end

# Set class-wide base_dir
def self.base_dir=(dir_path)
@@base_dir = dir_path
end

# Disable Marshaling cached items to disk
def self.disable_disk_cache!
@@disk_cache_enabled = false
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/site.rb
Expand Up @@ -425,6 +425,7 @@ def site_cleaner

# Disable Marshaling cache to disk in Safe Mode
def configure_cache
Jekyll::Cache.base_dir = in_source_dir(config["cache_dir"], "Jekyll/Cache")
Jekyll::Cache.disable_disk_cache! if safe
end

Expand Down
10 changes: 7 additions & 3 deletions test/test_site.rb
Expand Up @@ -76,13 +76,17 @@ def read_posts
allow(File).to receive(:directory?).with(theme_dir("_sass")).and_return(true)
allow(File).to receive(:directory?).with(theme_dir("_layouts")).and_return(true)
allow(File).to receive(:directory?).with(theme_dir("_includes")).and_return(false)
allow(File).to receive(:directory?).with(
File.expand_path(".jekyll-cache/Jekyll/Cache/Jekyll--Cache")
).and_return(true)
site = fixture_site("theme" => "test-theme")
assert_equal [source_dir("_includes")], site.includes_load_paths
end

should "configure cache_dir" do
fixture_site.process
assert File.directory?(source_dir(".jekyll-cache", "Jekyll", "Cache"))
assert File.directory?(source_dir(".jekyll-cache", "Jekyll", "Cache", "Jekyll--Cache"))
end
end

context "creating sites" do
setup do
@site = Site.new(site_configuration)
Expand Down