Implement render_cached helper
What does this MR do?
This is based on the API::Helpers::Caching#present_cached method that we use for some Grape API endpoints.
Since that is specific for Grape API endpoints, we need something that can work on Rails controllers. This exposes a new render_cached
helper when Gitlab::Caching::Helpers
module is included in a Rails controller.
Currently uses the same method signature but the render_cached
method calls render
instead of just calling body
with the precompiled json. This is to ensure that the behavior when render
is called is kept.
Tested this in a PoC merge request (!63644 (closed)) and it shows promising results for Projects::MergeRequestsController#discussions
as it dropped the response time from ~9s to ~1.5s in a large MR scenario (100+ discussions).
Does this MR meet the acceptance criteria?
Conformity
-
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.)
Related #332967 (closed)