Module: Gitlab::Cache::Helpers
- Included in:
- API::Helpers::Caching, IssuableActions, Projects::MergeRequests::DiffsController, Projects::MergeRequestsController
- Defined in:
- lib/gitlab/cache/helpers.rb
Constant Summary collapse
- DEFAULT_EXPIRY =
1.day
Instance Method Summary collapse
- #cache ⇒ ActiveSupport::Cache::Store
- #render_cached(obj_or_collection, with:, cache_context: ->(_) { current_user&.cache_key }, expires_in: Gitlab::Cache::Helpers::DEFAULT_EXPIRY, **presenter_args) ⇒ Object
Instance Method Details
#cache ⇒ ActiveSupport::Cache::Store
10 11 12 |
# File 'lib/gitlab/cache/helpers.rb', line 10 def cache Rails.cache end |
#render_cached(obj_or_collection, with:, cache_context: ->(_) { current_user&.cache_key }, expires_in: Gitlab::Cache::Helpers::DEFAULT_EXPIRY, **presenter_args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gitlab/cache/helpers.rb', line 14 def render_cached(obj_or_collection, with:, cache_context: ->(_) { current_user&.cache_key }, expires_in: Gitlab::Cache::Helpers::DEFAULT_EXPIRY, **presenter_args) json = if obj_or_collection.is_a?(Enumerable) cached_collection( obj_or_collection, presenter: with, presenter_args: presenter_args, context: cache_context, expires_in: expires_in ) else cached_object( obj_or_collection, presenter: with, presenter_args: presenter_args, context: cache_context, expires_in: expires_in ) end render Gitlab::Json::PrecompiledJson.new(json) end |