module ActionView::CollectionCaching

def fetch_or_cache_partial(cached_partials, template, order_by:)

written back to the underlying cache store.
If the partial is not already cached it will also be

corresponds to the first element in `rendered_partials`.
Order it so that the first empty cache element in `cached_partials`
for each element that was not found in the cache and store it as an array.
partial. An example is to render all results
This method expects a block that will return the rendered

otherwise `Hash#fetch` will take the value of its block.
it represents the rendered partial from the cache
`cached_partials` is a hash. If the value exists

all keys are passed in whether found already or not.
`order_by` is an enumerable object containing keys of the cache,
def fetch_or_cache_partial(cached_partials, template, order_by:)
  entries_to_write = {}
  keyed_partials = order_by.index_with do |cache_key|
    if content = cached_partials[cache_key]
      build_rendered_template(content, template)
    else
      rendered_partial = yield
      body = rendered_partial.body
      # We want to cache buffers as raw strings. This both improve performance and
      # avoid creating forward compatibility issues with the internal representation
      # of these two types.
      if body.is_a?(ActionView::OutputBuffer) || body.is_a?(ActiveSupport::SafeBuffer)
        body = body.to_str
      end
      entries_to_write[cache_key] = body
      rendered_partial
    end
  end
  unless entries_to_write.empty?
    collection_cache.write_multi(entries_to_write)
  end
  keyed_partials
end