Permalink
Browse files

Change site.config.cache_enable to a callback

  • Loading branch information...
1 parent ce0d9a2 commit 446ec048144ba4819dde2f057e36c1e108ba56b6 @aceofspades committed Jul 20, 2012
Showing with 8 additions and 4 deletions.
  1. +1 −1 README.md
  2. +1 −1 app/controllers/caloris/pages_controller.rb
  3. +1 −1 app/models/caloris/page.rb
  4. +5 −1 app/models/caloris/site.rb
View
@@ -81,7 +81,7 @@ Caloris.configure do |config|
config.root = File.expand_path('cms_content', Rails.root)
end
config.default_page_template = 'plain'
- config.cache_enable = Rails.env.production?
+ config.cache_enable = proc { |controller, page| Rails.env.production? }
config.metadata_schema = {
page_information: {
page_id: :string,
@@ -156,7 +156,7 @@ def maybe_cached_render(page)
block = proc do |page|
render_to_string inline: page.render, layout: false
end
- if page.cache_enable
+ if page.cache_enable && page.site.cache_enable(self, page)
key = ActionCachePath.new(self, params).path
if params[:expire_cache]
@@ -78,7 +78,7 @@ def body
# @returns [Boolean] true if page should be cached
def cache_enable
- metadata['cache_enable'] == 'true' || @site.cache_enable
+ metadata['cache_enable'] != 'false'
end
# @returns [Integer] number of seconds to cache page
@@ -52,7 +52,7 @@ def initialize site, &block
@formats = %w(html html.erb)
@storage = {git: {branch: 'master'}}
- @cache_enable = false
+ @cache_enable = proc { |controller, page| false }
@cache_expiration = 5.minutes
@cache_public = true
@@ -282,6 +282,10 @@ def metadatum_type key
flattened_metadata_schema[key]
end
+ def cache_enable controller, page
+ config.cache_enable.call(controller, page)
+ end
+
private
def asset_directories

0 comments on commit 446ec04

Please sign in to comment.