mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
remove rack cache, it has been causing trouble
instead implement an aggressive anonymous cache that is stored in redis this cache is sitting in the front of the middleware stack enabled only in production TODO: expire it more intelligently when stuff is created
This commit is contained in:
@ -155,35 +155,15 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def can_cache_content?
|
||||
# Don't cache unless we're in production mode
|
||||
return false unless Rails.env.production? || Rails.env == "profile"
|
||||
|
||||
# Don't cache logged in users
|
||||
return false if current_user.present?
|
||||
|
||||
true
|
||||
!current_user.present?
|
||||
end
|
||||
|
||||
# Our custom cache method
|
||||
def discourse_expires_in(time_length)
|
||||
return unless can_cache_content?
|
||||
expires_in time_length, public: true
|
||||
Middleware::AnonymousCache.anon_cache(request.env, 1.minute)
|
||||
end
|
||||
|
||||
# Helper method - if no logged in user (anonymous), use Rails' conditional GET
|
||||
# support. Should be very fast behind a cache.
|
||||
def anonymous_etag(*args)
|
||||
if can_cache_content?
|
||||
yield if stale?(*args)
|
||||
|
||||
# Add a one minute expiry
|
||||
expires_in 1.minute, public: true
|
||||
else
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def fetch_user_from_params
|
||||
username_lower = params[:username].downcase
|
||||
username_lower.gsub!(/\.json$/, '')
|
||||
|
Reference in New Issue
Block a user