mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Enable use of Action Caching in the API 🎉
See: https://guides.rubyonrails.org/api_app.html#adding-other-modules
This commit is contained in:
20
app/models/concerns/api_action_caching.rb
Normal file
20
app/models/concerns/api_action_caching.rb
Normal 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
|
||||
Reference in New Issue
Block a user