mirror of https://github.com/mastodon/mastodon
Change unauthenticated responses to be cached in REST API (#24348)
parent
c35e3cb6ac
commit
6084461cd0
@ -1,8 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1::CustomEmojisController < Api::BaseController
|
||||
vary_by ''
|
||||
|
||||
def index
|
||||
expires_in 3.minutes, public: true
|
||||
cache_even_if_authenticated!
|
||||
render_with_cache(each_serializer: REST::CustomEmojiSerializer) { CustomEmoji.listed.includes(:category) }
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module ApiCachingConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def cache_if_unauthenticated!
|
||||
expires_in(15.seconds, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.day) unless user_signed_in?
|
||||
end
|
||||
|
||||
def cache_even_if_authenticated!
|
||||
expires_in(5.minutes, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.day) unless whitelist_mode?
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue