From 975afb3152b8976c62cda2c447696414eb13a571 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 22 Apr 2020 12:35:39 +0200 Subject: [PATCH] Enable use of Action Caching in the API :tada: See: https://guides.rubyonrails.org/api_app.html#adding-other-modules --- app/models/concerns/api_action_caching.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/models/concerns/api_action_caching.rb 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