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:
Sam
2013-10-16 16:39:18 +11:00
parent ff966e3276
commit 3d647a4b41
12 changed files with 180 additions and 115 deletions

View File

@ -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$/, '')