Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Set public cache header expires for avatar

Oliver Günther2e9bbd30d543
diff --git a/modules/avatars/lib/api/v3/users/user_avatar_api.rb b/modules/avatars/lib/api/v3/users/user_avatar_api.rb
index 3ac4e95734b..481a9cc7cc8 100644
--- a/modules/avatars/lib/api/v3/users/user_avatar_api.rb
+++ b/modules/avatars/lib/api/v3/users/user_avatar_api.rb
@@ -35,6 +35,11 @@ module API
helpers ::API::Helpers::AttachmentRenderer
get '/avatar' do
+ # Cache for one day
+ expire_in = 60 * 60 * 24
+ header "Cache-Control", "public, max-age=#{expire_in}"
+ header "Expires", CGI.rfc1123_date(Time.now.utc + expire_in)
+
if local_avatar = local_avatar?(@user)
respond_with_attachment(local_avatar)
elsif avatar_manager.gravatar_enabled?