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
      if fragment = rendered_partial.body&.to_str
        entries_to_write[cache_key] = fragment
      end
      rendered_partial
    end
  end
  unless entries_to_write.empty?
    collection_cache.write_multi(entries_to_write)
  end
  keyed_partials
end