diff --git a/app/models/concerns/api_action_caching.rb b/app/models/concerns/api_action_caching.rb new file mode 100644 index 0000000000..ef0eba604d --- /dev/null +++ b/app/models/concerns/api_action_caching.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# API controllers inherit from ActionController::Metal to keep them slim and fast. +# This concern adds the minimum requirements needed to use Action Caching in the API. + +module ApiActionCaching + extend ActiveSupport::Concern + + included do + include ActionController::Caching + include ActionController::Caching::Actions + include AbstractController::Layouts + + # This config is not passed to the controller automatically with ActionController::Metal + self.cache_store = Rails.configuration.cache_store + + # ActionController::Caching asks for a controller's layout, but they're not used in the API + layout false + end +end