Commit 7363428c authored by Sean McGivern's avatar Sean McGivern

Merge branch 'tz-user-avatar-caching' into 'master'

Changed the Caching of User Avatars to be public and to 5 minutes

See merge request gitlab-org/gitlab-ce!24546
parents f02be29e 2d057da1
......@@ -29,7 +29,13 @@ module UploadsActions
def show
return render_404 unless uploader&.exists?
expires_in 0.seconds, must_revalidate: true, private: true
if cache_publicly?
# We need to reset caching from the applications controller to get rid of the no-store value
headers['Cache-Control'] = ''
expires_in 5.minutes, public: true, must_revalidate: false
else
expires_in 0.seconds, must_revalidate: true, private: true
end
disposition = uploader.image_or_video? ? 'inline' : 'attachment'
......@@ -114,6 +120,10 @@ module UploadsActions
nil
end
def cache_publicly?
false
end
def model
strong_memoize(:model) { find_model }
end
......
......@@ -70,6 +70,10 @@ class UploadsController < ApplicationController
end
end
def cache_publicly?
User === model || Appearance === model
end
def upload_model_class
MODEL_CLASSES[params[:model]] || raise(UnknownUploadModelError)
end
......
......@@ -12,6 +12,12 @@ shared_examples 'content not cached without revalidation and no-store' do
end
end
shared_examples 'content publicly cached' do
it 'ensures content is publicly cached' do
expect(subject['Cache-Control']).to eq('max-age=300, public')
end
end
describe UploadsController do
let!(:user) { create(:user, avatar: fixture_file_upload("spec/fixtures/dk.png", "image/png")) }
......@@ -184,7 +190,7 @@ describe UploadsController do
expect(response).to have_gitlab_http_status(200)
end
it_behaves_like 'content not cached without revalidation and no-store' do
it_behaves_like 'content publicly cached' do
subject do
get :show, params: { model: 'user', mounted_as: 'avatar', id: user.id, filename: 'dk.png' }
......@@ -201,7 +207,7 @@ describe UploadsController do
expect(response).to have_gitlab_http_status(200)
end
it_behaves_like 'content not cached without revalidation' do
it_behaves_like 'content publicly cached' do
subject do
get :show, params: { model: 'user', mounted_as: 'avatar', id: user.id, filename: 'dk.png' }
......@@ -537,7 +543,7 @@ describe UploadsController do
expect(response).to have_gitlab_http_status(200)
end
it_behaves_like 'content not cached without revalidation' do
it_behaves_like 'content publicly cached' do
subject do
get :show, params: { model: 'appearance', mounted_as: 'header_logo', id: appearance.id, filename: 'dk.png' }
......@@ -557,7 +563,7 @@ describe UploadsController do
expect(response).to have_gitlab_http_status(200)
end
it_behaves_like 'content not cached without revalidation' do
it_behaves_like 'content publicly cached' do
subject do
get :show, params: { model: 'appearance', mounted_as: 'logo', id: appearance.id, filename: 'dk.png' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment