Skip to content

Instantly share code, notes, and snippets.

@mattbrailsford
Created April 30, 2013 08:19
Show Gist options
  • Save mattbrailsford/5487346 to your computer and use it in GitHub Desktop.
Save mattbrailsford/5487346 to your computer and use it in GitHub Desktop.
@{
var myModel = new MyModelObj();
myModel.SomeProp = "Hello";
}
@Html.CachedPartial("MyPartialName", myModel, 3600)
@{
myModel.SomeProp = "World";
}
@Html.CachedPartial("MyPartialName", myModel, 3600)
@mattbrailsford
Copy link
Author

Assuming MyPartialName simply outputs @model.SomeProp, the result of both partials will both be "Hello" even though the model is updated to "World" for the second call to the partial. This is because the partial is cached, and so regardless of whether the model data changes, the cached result of the first call to the partial will always be returned until the cache expires.

Ultimately, what they are saying is, changes to the model do NOT expire the cache. So you need to be carefull if your partials make use of dynamic data (such as a paged grid of products).

@netaddicts
Copy link

Ok, get the point in your example, and assume the same goes for data passed in as a ViewDataDictionary object, so makes this example rather useless if you need more control over your caching (ie based on querystrings, cookie values) as we could in v4 (standard macro's)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment