Added contextualKeyBuilder optional argument to allow the key used for cachin... #143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
...g to be contextual.
when building cached partials that work with many different instances of the same partial view (e.g. using the same partial more than once on a page with different ViewDataDictionary or different model), it is necessary to either name each instance differently (ugh), or not cache.
By adding an optional argument to the CachedPartial Html helper method, we can vary the cache-key depending on the context of insertion. For maximum flexibility, pass the model and the viewData to the function so it can use that data to format a cacheKey suffix.
A typical use would be something like:
@Html.CachedPartial(
"EventListings"
, FeedRepository.getFeed(new CalendarEventsModel
{
StartingDate = DateTime.UtcNow.Date
, Count = 10
})
, 0
, contextualKeyBuilder: (model, viewData) =>
{
return (model as CalendarEventsModel).StartingDate.ToString();
}
)