mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:01:14 +08:00
Don't enable Cache-Control if the site has restricted access.
This commit is contained in:
@ -135,14 +135,33 @@ class ApplicationController < ActionController::Base
|
|||||||
render json: MultiJson.dump(obj)
|
render json: MultiJson.dump(obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_cache_content?
|
||||||
|
# Don't cache unless we're in production mode
|
||||||
|
return false unless Rails.env.production?
|
||||||
|
|
||||||
|
# Don't cache logged in users
|
||||||
|
return false if current_user.present?
|
||||||
|
|
||||||
|
# Don't cache if there's restricted access
|
||||||
|
return false if SiteSetting.restrict_access?
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
# Our custom cache method
|
||||||
|
def discourse_expires_in(time_length)
|
||||||
|
return unless can_cache_content?
|
||||||
|
expires_in time_length, public: true
|
||||||
|
end
|
||||||
|
|
||||||
# Helper method - if no logged in user (anonymous), use Rails' conditional GET
|
# Helper method - if no logged in user (anonymous), use Rails' conditional GET
|
||||||
# support. Should be very fast behind a cache.
|
# support. Should be very fast behind a cache.
|
||||||
def anonymous_etag(*args)
|
def anonymous_etag(*args)
|
||||||
if current_user.blank? and Rails.env.production?
|
if can_cache_content?
|
||||||
yield if stale?(*args)
|
yield if stale?(*args)
|
||||||
|
|
||||||
# Add a one minute expiry
|
# Add a one minute expiry
|
||||||
expires_in 1.minute, :public => true
|
expires_in time_length, public: true
|
||||||
else
|
else
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
@ -58,8 +58,7 @@ class ListController < ApplicationController
|
|||||||
draft = Draft.get(current_user, list.draft_key, list.draft_sequence) if current_user
|
draft = Draft.get(current_user, list.draft_key, list.draft_sequence) if current_user
|
||||||
list.draft = draft
|
list.draft = draft
|
||||||
|
|
||||||
# Add expiry of 1 minute for anonymous
|
discourse_expires_in 1.minute
|
||||||
expires_in 1.minute, :public => true if current_user.blank?
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
|
Reference in New Issue
Block a user