diff --git a/app/controllers/user_avatars_controller.rb b/app/controllers/user_avatars_controller.rb index db47e4b701f..1007760b13d 100644 --- a/app/controllers/user_avatars_controller.rb +++ b/app/controllers/user_avatars_controller.rb @@ -192,7 +192,9 @@ class UserAvatarsController < ApplicationController end def redirect_s3_avatar(url) - immutable_for 1.day + response.cache_control[:max_age] = 1.hour.to_i + response.cache_control[:public] = true + response.cache_control[:extras] = ["immutable", "stale-while-revalidate=#{1.day.to_i}"] redirect_to url, allow_other_host: true end diff --git a/spec/requests/user_avatars_controller_spec.rb b/spec/requests/user_avatars_controller_spec.rb index db4146208a9..0d5a7973e73 100644 --- a/spec/requests/user_avatars_controller_spec.rb +++ b/spec/requests/user_avatars_controller_spec.rb @@ -139,7 +139,9 @@ RSpec.describe UserAvatarsController do expect(response.status).to eq(302) expect(response.location).to eq("https://s3-cdn.example.com/optimized/path") - expect(response.headers["Cache-Control"]).to eq("max-age=86400, public, immutable") + expect(response.headers["Cache-Control"]).to eq( + "max-age=3600, public, immutable, stale-while-revalidate=86400", + ) end it "serves new version for old urls" do