moonpyk / mvcdonutcaching

ASP.NET MVC Extensible Donut Caching brings donut caching to ASP.NET MVC 3 and later. The code allows you to cache all of your page apart from one or more Html.Actions which can be executed every request. Perfect for user specific content.
https://github.com/moonpyk/mvcdonutcaching
MIT License
142 stars 50 forks source link

MvcDonutCaching doesn't work on ChildActions? #55

Closed Mds92 closed 8 years ago

Mds92 commented 8 years ago

I'm using MVC 5.2.3. I have a PartialView that I used it in _Layout.cshtml as the following: @Html.Action("TopMenu", "Home", true) But MvcDonutCaching doesn't work and TopMenu get cached as normal

[ChildActionOnly]
[DonutOutputCache(Duration = 60)]
public PartialViewResult TopMenu()
{
    return PartialView("~/Views/Partials/TopMenuPartial.cshtml");
}
jbreuer commented 8 years ago

Do you have a child action in a child action? https://mvcdonutcaching.codeplex.com/discussions/324905

jbreuer commented 8 years ago

Sorry that was an old issue. It's a setting. Just got it working :-) https://github.com/moonpyk/mvcdonutcaching/issues/13#issuecomment-38908957

Mds92 commented 8 years ago

Not at all, @Html.Action("TopMenu", "Home", true) is my _Layout.cshtml and my TopMenuPartial.cshtml is as the following:

@using Smartiz.Common
@using Smartiz.Security
@{
    Layout = null;
}
<div class="navbar navbar-inverse">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
    </div>
    <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav">
            <li><a href="@ViewBag.WebsiteDomain">صفحه نخست</a></li>
            @if (!Request.IsAuthenticated)
            {
                <li>@Html.ActionLink("ورود", "Login", "Account")</li>
                <li>@Html.ActionLink("عضویت در سایت", "Register", "Account")</li>
            }
            else
            {
                <li>@Html.ActionLink(SecurityContext.CurrentUser.FullName, "UserSpecification", "Account")</li>
                if (SecurityContext.CurrentUser.IsAdmin)
                {
                    <li><a href="@StaticVariables.ControlPanelDomain" target="_blank">کنترل پنل</a></li>
                }
                <li>@Html.ActionLink("خروج", "LogOff", "Account")</li>
            }
        </ul>
        <ul class="nav navbar-nav navbar-left">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="fa fa-rss"></span></a>
                <ul class="dropdown-menu">
                    @if (ViewBag.SelectedSubject != null)
                    {
                        <li>
                            <a target="_blank" href="@Url.RouteUrl("ContentsRssBySubjectId", new {subjectId = ViewBag.SelectedSubject.Id})"
                               title="@string.Format("RSS اخبار برای موضوع {0}", ViewBag.SelectedSubject.Name)" data-name="rss-icon"><span class="fa fa-rss"></span>فید موضوع انتخاب شده</a>
                        </li>
                    }
                    else if (ViewBag.SelectedTag != null)
                    {
                        <li>
                            <a target="_blank" href="@Url.RouteUrl("ContentsRssByTag", new {tag = ViewBag.SelectedTag})"
                               title="@string.Format("RSS اخبار برای برچسب {0}", ViewBag.SelectedTag)" data-name="rss-icon"><span class="fa fa-rss"></span>فید برچسب انتخاب شده</a>
                        </li>
                    }
                    <li><a target="_blank" href="@Url.RouteUrl("DeviceRss")" title="RSS" data-name="rss-icon"><span class="fa fa-rss"></span> فید دستگاه ها</a></li>
                    <li><a target="_blank" href="@Url.RouteUrl("DevicesCompareRss")" title="RSS" data-name="rss-icon"><span class="fa fa-rss"></span> فید مقایسه ها</a></li>
                    <li><a target="_blank" href="@Url.RouteUrl("ContentsRss")" title="RSS" data-name="rss-icon"><span class="fa fa-rss"></span> فید محتویات</a></li>
                </ul>
            </li>
            <li>@Html.ActionLink("تبلیغات", "Index", "Advertisement")</li>
            <li>@Html.ActionLink("تماس با ما", "Index", "ContactUs")</li>
            <li>@Html.ActionLink("درباره ما", "Index", "AboutUs")</li>

        </ul>
    </div>
</div>
Mds92 commented 8 years ago

I set the following setting:

protected void Application_Start()
{
...
DevTrends.MvcDonutCaching.OutputCache.DefaultOptions = DevTrends.MvcDonutCaching.OutputCacheOptions.ReplaceDonutsInChildActions;
...
}

But nothing change and my child action get cached again !!!

Mds92 commented 8 years ago

I found the problem, I didn't use DonutOutputCache attribute for output cache on actions, I used OutPutCache instead. I changed it to DonutOutputCache, my problem solved. Thanks