Some of you find it useful

Listing of my everyday findings about .NET

  • nature
  • nature
  • nature
  • nature
  • nature
  • nature

Donut Caching with ASP.NET Substitution control

by tariqulazam

We all are using ASP.NET Caching features to improve the performance of our site and we all know about very widely used caching terms like 'Output caching','Fragment Caching' etc. For those who are not familiar Google is your friend.

Today I am not going to show how caching can be used rather I will describe a hidden gem in the cache infrastructure of ASP.NET. I am calling it hidden and Gem at the same time as I did not encounter any scenario before where this could be used (or I did not even think about caching…) and where applicable it could be very handy. It’s called ‘Donut caching’ and as the name implies, it is like a hole in the cached output where you can programmatically set value.

Let me tell you the scenario that I encounter today at work. We have a fairly large application and we are in the process of optimizing the performance of that application. It has got a Header User Control and a couple of controls in the header are populated based on logged in user roles. The logged in user name also displayed in the header. For some database operation heavy page (search result page), we want to implement output caching, but the barrier was the header control. We do not want to redesign the page and encapsulate the search result grid into another User control and implement fragment caching there. Here comes the ASP.NET Substitution control in our rescue.

To start with, let us look at the mark-up of the Substitution control first.

<asp:substitution methodname="GetUserName" runat="Server" id="subUserName"></asp:substitution>

The html rendered by this control is the hole in the donut. The only important and useful bit is the MethodName property. It should reference a static method and should return a string. So whatever string you return from the GetUserName method will be rendered in the output. For displaying the logged name user name we have used the following method. For populating other controls we create the markup as necessary in the similar fashion.

 Public static string GetUserName(HttpContext context){  	       
         return Session["UserDisplayName"].ToString();   
 }  

So far, everything was easy, but I am pretty sure you will run into issue soon, as most of the developer depends on Session for keeping some user specific information, like Display Name, etc. The above mentioned code will work fine on the first instance but you will encounter a NullReference exception when you come back to the page later. It is because, for the cache version of the page, the page was never created and hence no session. Despite this limitation, asp:Substitution is a very handy control, that could save you some of your time and headache.

I have attached a very simple website project here. Download it and see the asp:substitution control in action. I hope that helps and give you an idea when and how to use the substitution control.

Post category: ASP.NET, C#

Comments

Re: Donut Caching with ASP.NET Substitution control
Monday, March 26, 2012 12:49 PM by Dectgorremo

[url=http://pornfreetube.ru/][img]http://pornfreetube.ru/pt/5620e5ec08.jpg [/img][/url] [url=http://pornfreetube.ru/][img]http://pornfreetube.ru/pt/8d917d80e0.jpg [/img][/url] [b]????? ????????? [/b] - [url=http://pornfreetube.ru/]????? ???? [/url]

Re: Donut Caching with ASP.NET Substitution control
Saturday, April 07, 2012 2:29 AM by Lanette

viagra without a prescription thygix life insurance =]] auto insurance quotes =-[

Re: Donut Caching with ASP.NET Substitution control
Saturday, April 07, 2012 5:47 AM by Peaxrairwes

[url=http://freepornporno.com/][img]http://freepornporno.com/img/thumb/167454_1.jpg [/img][/url] [url=http://freepornporno.com/][img]http://freepornporno.com/img/thumb/169477_1.jpg [/img][/url] [b]free porn tube videos com [/b] - [url=http://freepornporno.com/]free granny porn tube [/url] [url=http://www.pinkcookiedesign.com/board/member/34434/]free porn tube homemade [/url]

Re: Donut Caching with ASP.NET Substitution control
Sunday, April 08, 2012 4:25 AM by priorieGemi

[url=http://porn-online-free.com/][img]http://porn-online-free.com/img/thumb/171529_0.jpg [/img][/url] [url=http://porn-online-free.com/][img]http://porn-online-free.com/img/thumb/171521_1.jpg [/img][/url] [b]kraddy android porn ??????? [/b] - [url=http://porn-online-free.com/]porn pics [/url] [url=http://forum.begemot.dp.ua/memberlist.php?mode=viewprofile&u=163904]porn chat [/url]

Re: Donut Caching with ASP.NET Substitution control
Sunday, April 08, 2012 8:42 PM by MypeAbseste

[url=http://pornfreebest.com/][img]http://pornfreebest.com/img/thumb/171633_1.jpg [/img][/url] [url=http://pornfreebest.com/][img]http://pornfreebest.com/img/thumb/171625_1.jpg [/img][/url] [b]best porn tracker [/b] - [url=http://pornfreebest.com/]best porn pics [/url] [url=http://burntracs.com/tracsbook/index.php?topic=59559.0]best free porn [/url][url=http://arhipka.ru/forum/member.php?u=80157]porn best mature [/url]

Re: Donut Caching with ASP.NET Substitution control
Tuesday, April 10, 2012 9:56 PM by Ruiguicaicy

[url=http://pornfreefor.com/][img]http://pornfreefor.com/img/thumb/171709_1.jpg [/img][/url] [url=http://pornfreefor.com/][img]http://pornfreefor.com/img/thumb/171707_1.jpg [/img][/url] [b]anal sex video [/b] - [url=http://pornfreefor.com/]sex russkoe video [/url] [url=http://lsmobile.bbs.fc2.com/]porn video young home [/url][url=http://ngame.com.ua/user/extippisa/]azeri sex video [/url]

Re: Donut Caching with ASP.NET Substitution control
Friday, April 13, 2012 1:09 AM by Fluolaunfosse

[url=http://pornpornofree.com/][img]http://pornpornofree.com/img/thumb/172169_1.jpg [/img][/url] [url=http://pornpornofree.com/][img]http://pornpornofree.com/img/thumb/172189_1.jpg [/img][/url] [b]boom porno tube [/b] - [url=http://pornpornofree.com/]dp tube porno [/url] [url=http://images.cocika.com/?level=picture&id=68#comment-post]young porno tube [/url][url=http://zdraviyajelayu.com.ua/forum/memberlist.php?mode=viewprofile&u=9952]www porno tube net [/url]

Re: Donut Caching with ASP.NET Substitution control
Saturday, April 14, 2012 9:36 PM by HaimbHoodabuh

[url=http://1sexporn.ru/][img]http://1sexporn.ru/img/thumb/149608_1.jpg [/img][/url] [url=http://1sexporn.ru/]????? ????? hd torrent [/url] [url=http://1xxxfreeporn.ru/][img]http://1xxxfreeporn.ru/img/thumb/152260_1.jpg [/img][/url] [url=http://1xxxfreeporn.ru/]?????????? ????? ????? ????? [/url] [url=http://2sexporn.ru/][img]http://2sexporn.ru/img/thumb/149607_1.jpg [/img][/url] [url=http://2sexporn.ru/]??????? ???? ??????? [/url] [url=http://2xxxfreeporn.ru/][img]http://2xxxfreepor

Re: Donut Caching with ASP.NET Substitution control
Sunday, May 06, 2012 5:15 AM by Lotoheame

[url=http://porn-for-free-xxx.ru/][img]http://porn-for-free-xxx.ru/scj/thumbs/0/942.jpg [/img][/url] [url=http://porn-for-free-xxx.ru/][img]http://porn-for-free-xxx.ru/scj/thumbs/0/296.jpg [/img][/url] [b]?????????? ??????? ????? ??????????? [/b] - [url=http://porn-for-free-xxx.ru/]???????? ????????? ????? ?????? [/url] ???????? ???????? ????? ?????? ?????????? ??????? ????? ????? ???????? ????? +? ???? ???????? ?????????? ????? ????????? ???????? ????? ?????? ????????? [url=h

Re: Donut Caching with ASP.NET Substitution control
Sunday, May 06, 2012 4:47 PM by PymnlyncSaunc

[url=http://porn-for-free-xxx.ru/][img]http://porn-for-free-xxx.ru/scj/thumbs/0/462.jpg [/img][/url] [url=http://porn-for-free-xxx.ru/][img]http://porn-for-free-xxx.ru/scj/thumbs/0/522.jpg [/img][/url] [b]???????? ????? ?????? ?????? ???? [/b] - [url=http://porn-for-free-xxx.ru/]?????????? ????? ???? ??????? ???????? [/url] ???????? ??????? ????? +? ????????? ????? ?????? ?????? ???????? ???? ????? ?????????????? ????? ??????? ?????? +??? ??? ????? ???????? ????????? ????????????

Re: Donut Caching with ASP.NET Substitution control
Monday, May 07, 2012 7:22 AM by Vorpayomiagom

[url=http://porn-for-free-xxx.ru/][img]http://porn-for-free-xxx.ru/scj/thumbs/0/420.jpg [/img][/url] [url=http://porn-for-free-xxx.ru/][img]http://porn-for-free-xxx.ru/scj/thumbs/0/890.jpg [/img][/url] [b]???????????? ????? ?????? ???????? ????????? [/b] - [url=http://porn-for-free-xxx.ru/]???????? ????? ?????? ???? ??? [/url] ???????? ????? ???? ???2 ?????? ??? ??????? ????? ????????? ???????? ?????? ??????? ????? ????????? ??????? ????? ????? ???? ????? ?????? ???????? [url=

Re: Donut Caching with ASP.NET Substitution control
Monday, May 07, 2012 4:58 PM by Vellbriedegab

easy payday loans uk [url=http://www.uk-best-payday-loans.com/]cash loan [/url] pay day loans online [url=http://www.aaacalgarypaydayloans.com/]fast payday loans canada [/url] payday bad credit loans [url=http://www.uk-fast-payday-loans.com/]instant payday loans no credit checks [/url] payday direct loans

Re: Donut Caching with ASP.NET Substitution control
Tuesday, May 08, 2012 6:03 PM by Adefawvaw

??? ??? ?? ? ??? ?? ????????. ?????? ???? ?????????? ?? ?? ?? ???? ?? ???????, ?? ?? ?? ????? ??????????. ???? ?????? ?? ????? ?????? ???????. ????? ?????? ??? ??? ? ???????? ????-?? ????????????, ?? ????? ?? ? ???, ?? ????? ??????? ????? ? ????? ????????... ??? ??? ? ????, ?? ? ??? ??????? ??? ??????????? ?????. ??? ????? ???? ???? ??????? ?????? ? ? ???? ?? ???? ????? ?? ? ??????? ????. ??????? ????????? ?????????? ? ?????. ? ??? ??? ????, ??? ??? ????? ?????? ????????????, ?????????? ?? ?????

Re: Donut Caching with ASP.NET Substitution control
Thursday, May 10, 2012 12:02 AM by SmitlyUtili

[url=http://online-porn-movie.ru/][img]http://online-porn-movie.ru/pt/c0dad5d554.jpg [/img][/url][url=http://online-porn-movie.ru/][img]http://online-porn-movie.ru/pt/a074557325.jpg [/img][/url] [url=http://online-porn-movie.ru/]???????? ?????????? ????? [/url]. - ? ??? ? ??, ?????????. ?????? ????????? ???? ?????????? ?????????… ????? ????? ???????? ??????? ? ? ???? ???-?? ???? ??????: ??????, ????, ??????? ?? ???????. ???????? ??? ?? ?????? ??-?? ???? ? ???????, ??????? ???????? ????????. ??

Re: Donut Caching with ASP.NET Substitution control
Saturday, May 19, 2012 8:16 PM by Ricrorytody

?????????? ??????? ????? ????? [url=http://twitter.com/#!/PornVideoPornru]????? ????? ?????? ????? ??????? [/url]?????????? ????? ????? ????????

Leave a comment

* indicates required fields.


Subscribe to RSS

Recent Posts

Recently Added Links

Article Archive

Article Categories

Article Tag Cloud

application performance asp.net c# caching cdn conditional get css design pattern donut caching etag html5 javascript n-tier application oop tips and tricks visual studio website performance

Links Categories

Link Tag Cloud

.net ado.net asp.net c# deployment design pattern entity data model features iphone jquery monotouch oop performance ria service silverlight tutorial video wcf website performance website project

Visitor Map