3

Two questions:

1. If I have a content page and a master page and I put this inside my content page:

<%@ OutputCache ...%>

Does it cache the whole page or only the content page portion?

2. How can I apply OutputChace in the master page?

I have a master page that has a lot of content pages that uses it. I want to apply the same outputcache profile on all of them, but I dont want to go one by one and change them.

Thanks.

TheTechGuy
  • 16,560
  • 16
  • 115
  • 136
Nir
  • 2,497
  • 9
  • 42
  • 71
  • i want to apply the OutputCache in the content page level only how could i define the the content page as a portion only . i don't want the rest of the master page cached since change could apply to it , not regarding the content . – eran otzap Sep 25 '11 at 20:33

2 Answers2

1

The whole page is cached. Edit
You can use user controls to cache portions.

As by the comments, if you want to cache all pages that are using a specific master page, you need the following code in the master page

 protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
            Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
            Response.Cache.SetValidUntilExpires(true);
        }
Adrian Iftode
  • 15,465
  • 4
  • 48
  • 73
  • And if I want to apply OutputChace in the master page level, how can I accomplish this? – Nir Jul 04 '11 at 20:43
  • 1
    I believe you are dealing with some heavy load menu. You can put it in an user control and cache it from there. Any portion in master page you need it to cache put it in an user control (header, menu, footer, left menu...). That's the easiest way you can do it. – Adrian Iftode Jul 04 '11 at 20:48
  • I have a master page the a lot of content pages uses it. I want to apply the same outputcache profile on all of them, but I dont want to go one by one and change them. – Nir Jul 04 '11 at 20:50
  • Edit your question so I can add an answer, because I can't post here the formatted code – Adrian Iftode Jul 04 '11 at 21:02
  • What if I want to cache it in the server, client and proxy? – Nir Jul 04 '11 at 21:21
  • This instructs the client to cache it, I don't know how to cache the whole pages on server. – Adrian Iftode Jul 04 '11 at 21:33
0

Content page only will be cached; unless that content page is using the master page, in which case master page also will be cached.

Unlike a content page you can't use OutputCache directive for master page. See the below links

Cache Master Page in ASP.NET

http://www.dotnetperls.com/output-cache

http://forums.asp.net/t/1236981.aspx

Community
  • 1
  • 1
Rahul
  • 76,197
  • 13
  • 71
  • 125