<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Trailblazer's Sharepoint Blog : Fragment Caching</title><link>http://blogs.msdn.com/varun_malhotra/archive/tags/Fragment+Caching/default.aspx</link><description>Tags: Fragment Caching</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Fragment Caching for user controls doesn’t work in SharePoint if using SPD.</title><link>http://blogs.msdn.com/varun_malhotra/archive/2008/11/27/fragment-caching-for-user-controls-doesn-t-work-in-sharepoint-if-using-spd.aspx</link><pubDate>Thu, 27 Nov 2008 18:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9146816</guid><dc:creator>varunmalhotra</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/varun_malhotra/comments/9146816.aspx</comments><wfw:commentRss>http://blogs.msdn.com/varun_malhotra/commentrss.aspx?PostID=9146816</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;I recently had a strange requirement or should I say an issue where the client had created a user control in SharePoint and was trying to use Fragment Caching on the user control. But somehow the fragment caching wasn’t working. And the client was asking whether SharePoint actually Supports Fragment Caching or not?&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;On further investigation I found that he was adding the user control through SPD. After a couple of tests I found the following reason on why Fragment Caching wouldn’t work for SPD added User Controls.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;To understand the reason, I would like to touch base on how output caching/fragment caching works. Whenever you ask the control to be cached the output of the control is stored on the server. So that any request that comes for the page containing the control, the output is rendered straight from the cache and the code involved with the control is not executed again. The cache in this case is the server cache (Output saved on server). This would continue till the time the cache is invalidated.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Now let’s take a look how SPD works. Any customization which you do using SPD is stored in the database. So every request for this page, would bring the customized content from the database. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;Now let’s combine the two – SPD and caching. When you add the cached user controls from SPD, the user controls are added to the database. So even though you add the entries in SPD, the changes are not added to the file but to the database. So when the page is requested, the contents and particularly, the cached user controls are brought from the database. And this happens every time irrespective of the fact that output caching has been enabled for the controls. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;I researched and found that for controls that are added through SPD, since content comes from DB, no output is stored in the Server Cache and &lt;B&gt;hence fragment caching doesn’t work when you use SPD. &lt;/B&gt;So the problem is not with SharePoint, not even with the SPD, but with the way SPD works which cannot be combined with output caching.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;The workaround for this issue is to use one of the following:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN lang=EN-IN style="mso-bidi-font-family: Calibri; mso-ansi-language: EN-IN; mso-fareast-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;If you want to &lt;B&gt;show the user control on all pages&lt;/B&gt;:- This can be done by adding the user controls to the master page. &amp;nbsp;So take the following steps to achieve this:&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"&gt;&lt;SPAN lang=EN-IN style="mso-bidi-font-family: Calibri; mso-ansi-language: EN-IN; mso-fareast-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;a.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Check the master page being used by the site – CustomDefault.master.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"&gt;&lt;SPAN lang=EN-IN style="mso-bidi-font-family: Calibri; mso-ansi-language: EN-IN; mso-fareast-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;b.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Open the CustomDefault.master - master page in notepad or visual studio but not SPD. Add the two register tags and the instances of the user controls. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Register Tags:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;lt;%@ Register TagPrefix="wssuc" TagName="WellSet" src="~/_controltemplates/Cached.ascx" %&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;lt;%@ Register TagPrefix="wssuc" TagName="UnCached" src="~/_controltemplates/UnCached.ascx" %&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Add the instances somewhere after the &amp;lt;head&amp;gt; tag.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;lt;wssuc:Cached id="IdWellSet" runat="server"&amp;gt;&amp;lt;/wssuc:Cached&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in"&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;lt;wssuc:UnCached id="IdWellSet1" runat="server"&amp;gt;&amp;lt;/wssuc:UnCached&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 1in"&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"&gt;&lt;SPAN lang=EN-IN style="mso-bidi-font-family: Calibri; mso-ansi-language: EN-IN; mso-fareast-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;c.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;And that’s it and you are all set to use the user controls.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"&gt;&lt;SPAN lang=EN-IN style="mso-bidi-font-family: Calibri; mso-ansi-language: EN-IN; mso-fareast-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;d.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Now open the site and saw the output of the user controls and &lt;B&gt;Output Caching works perfectly &lt;/B&gt;for the Cached User Control. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in"&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoListParagraph style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;SPAN lang=EN-IN style="mso-bidi-font-family: Calibri; mso-ansi-language: EN-IN; mso-fareast-font-family: Calibri"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN lang=EN-IN style="mso-ansi-language: EN-IN"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;If you want to &lt;B&gt;show the user controls on one of the pages or a selected few&lt;/B&gt;: &amp;nbsp;The best and easy way to use this is to create a custom web part and add that web part to the gallery of the site. From the gallery you can go ahead and add web part to the selected page/s.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9146816" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/varun_malhotra/archive/tags/Varun+MAlhotra/default.aspx">Varun MAlhotra</category><category domain="http://blogs.msdn.com/varun_malhotra/archive/tags/Fragment+Caching/default.aspx">Fragment Caching</category></item></channel></rss>