Created
April 30, 2013 08:19
-
-
Save mattbrailsford/5487346 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
var myModel = new MyModelObj(); | |
myModel.SomeProp = "Hello"; | |
} | |
@Html.CachedPartial("MyPartialName", myModel, 3600) | |
@{ | |
myModel.SomeProp = "World"; | |
} | |
@Html.CachedPartial("MyPartialName", myModel, 3600) |
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
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).