Hello, so i have a problem i need to understand better.
I need to cache my side navigation.
I have it in a partial view, so i thought i could use the @html.CachePartial(),
but im new to all this caching,
so i dont know really how to cache it,
i might be able to make my own cache method but still, might not be the best/simplest.
This is my cache code,
@Html.CachedPartial("~/Views/Partials/Navigation/SideNavigation.cshtml", Model, 3600, true)
but could someone explain where or how to use it?
I've read this article
the last parameter here is saying to cache by page, meaning that instead of caching the content of the partial for the entire site, it is caching it for only that page (this is great for pages where you want to cache content managed content that is different between pages).
So this will cache the content of your nav partial and then any page that is loaded within 1hour (3600 seconds / 60), will get served the nav partial with the data from the cache, after that the cache will be renewed and then that content will get served for another 60mins, so on and so on,
So a good way to test this would be to use the code i have supplied above,
view the page and see the navigation and then in the cms, add a navigation item and see that the nav doesn't update until an hour later when the cache gets renewed.
NOTE:
There are no additional steps you need to take simply calling that line of code will handle all of the caching for you
Hello Louis, the caching now works, i tested it like you said, I made a new item in the nav, and when the cache renewed it was there, and i tested to see if the nav was there before the hour too, just in case.
But i have a question then, im using the nav in different places with different models, arent that gonna effect the output of that? i read that if you have different models, then the nav will just take the first model of where the the cached nav is (and the rest gets the same)?
So is this going to work if i go to for example, Vehicle -> Cars -> Doors,
and when it goes to doors page it shows where in the nav i am.
In the Nav on that page is the Vehicle -> Cars -> Doors.
Caching the navigation
Hello, so i have a problem i need to understand better.
I need to cache my side navigation. I have it in a partial view, so i thought i could use the @html.CachePartial(), but im new to all this caching, so i dont know really how to cache it, i might be able to make my own cache method but still, might not be the best/simplest. This is my cache code, @Html.CachedPartial("~/Views/Partials/Navigation/SideNavigation.cshtml", Model, 3600, true)
but could someone explain where or how to use it? I've read this article
https://our.umbraco.com/documentation/Reference/Templating/Mvc/partial-views
Hi Emil,
So they way you are using it there is slightly incorrect for the particular use case of a navigation,
the last parameter here is saying to cache by page, meaning that instead of caching the content of the partial for the entire site, it is caching it for only that page (this is great for pages where you want to cache content managed content that is different between pages).
So this code should work for your navigation:
So this will cache the content of your nav partial and then any page that is loaded within 1hour (3600 seconds / 60), will get served the nav partial with the data from the cache, after that the cache will be renewed and then that content will get served for another 60mins, so on and so on,
So a good way to test this would be to use the code i have supplied above, view the page and see the navigation and then in the cms, add a navigation item and see that the nav doesn't update until an hour later when the cache gets renewed.
NOTE:
There are no additional steps you need to take simply calling that line of code will handle all of the caching for you
Hello Louis, the caching now works, i tested it like you said, I made a new item in the nav, and when the cache renewed it was there, and i tested to see if the nav was there before the hour too, just in case.
But i have a question then, im using the nav in different places with different models, arent that gonna effect the output of that? i read that if you have different models, then the nav will just take the first model of where the the cached nav is (and the rest gets the same)?
So is this going to work if i go to for example, Vehicle -> Cars -> Doors, and when it goes to doors page it shows where in the nav i am. In the Nav on that page is the Vehicle -> Cars -> Doors.
This will ultimately depend on how you are retrieving your nav partial, could you provide the code?
Im doing is like ->
shouldnt i use the cachesPartial where i want the nav to be ?
but i dont think this is right, cus its calling the same state every time ?
I meant the code within that partial, it is correct im not sure what you mean by 'state'?
My bad,
This is what im using
King regards.
is working on a reply...