Enable use of Action Caching in the API 🎉

See: https://guides.rubyonrails.org/api_app.html#adding-other-modules
This commit is contained in:
Matt-Yorkley
2020-04-22 12:35:39 +02:00
parent ac166f3590
commit 975afb3152

View File

@@ -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