Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 18th, 2012, 09:52 AM
Authorized User
Points: 257, Level: 5
Points: 257, Level: 5 Points: 257, Level: 5 Points: 257, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Location: Healing, UK
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default %@OutputCache vs LoginView

Hi Imar,

I am hoping you can give me some more advice?

Through your tuition I have introduced Output Caching into my website to speed up loading and I have also added a Login View to my masterpage to show options for an anonymous user vs a logged in user. This is where the conflict of technologies comes into play.

Obviously, I have cached all pages using OutputCache but in so doing I realise that when I have logged into the site the Login View on the pages that I have already visited still show my anonymous user login information since this has been read from the cache and has not been reloaded since the login occurred.

After searching the internet I get the feeling that this is a common problem but I have not come across a solution as yet which is concise and deals with the issue in an efficient manner. I also get the feeling that this could be accomplished by correctly using one of the "VaryBy????" parameters of the OutputCache but I am not sure how to do this as yet?

Can you therefore give me some guidance on the best use of caching technologies when introducing controls such as the Login View control which needs to effectively change the cached page that currently exists.

Kind regards,

Ian Ryder.
Reply With Quote
  #2 (permalink)  
Old May 19th, 2012, 08:52 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Ian,

Here's an article that explains how to cache per user: http://www.zdnetasia.com/how-to-cach...s-39180129.htm

The question is: is that what you really want? The idea of an output cache is that you create a page once and then reuse it many times. If you create unique pages per user, there's a fair chace the cache gets full and pages get ejected without ever being visited again.

I personally wouldn't cache pages that contain user specific information and would focus on standard pages instead. If the data you're displaying is not unique to each user, you could cache that using the data controls or cache API.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old May 22nd, 2012, 09:50 AM
Authorized User
Points: 257, Level: 5
Points: 257, Level: 5 Points: 257, Level: 5 Points: 257, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Location: Healing, UK
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default Not Understanding Your Guidance?

Hi Imar,

Sorry for the delay in replying, being trying to get my head round this one?

Based on your comments each and every page of my site is a user specific page since I have placed the Login View control in the masterpage to display whether someone is logged in or not and they then have the ability to logout at anytime. This is what you have demonstrated designing the PlanetWrox site (knowing that you have NOT used outputcache on each page).

What I am struggling to get my head round, is that if you have a Login View in the masterpage then this implies that you CANNOT use the outputcache on any page since this will show incorrect information.

Knowing all that, can you please give me some more guidance on how I could effectively utilise either the cache of the Login View control or the Cache API in the masterpage to achieve what I think you realise is what I am trying to do.

Thanks for any further help you can give on this one Imar.

Cheers,

Ian Ryder.
Reply With Quote
  #4 (permalink)  
Old May 22nd, 2012, 09:56 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Ian,

The idea is to not cache the LoginView. Instead, disable output caching and then cache your data using aching on, for example, the SqlDataSource, or the cache API. This way, the complete page is constructed on each request, but the data that it displays is retrieved from the cache, and thus quick to generate.

You can also use thr Substitution control to do "doughnut caching". However, since it needs to return a string, it's not suitable for complex scenarios such as controls in a LogonView.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old May 22nd, 2012, 10:42 AM
Authorized User
Points: 257, Level: 5
Points: 257, Level: 5 Points: 257, Level: 5 Points: 257, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Location: Healing, UK
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default Chapter 15 Reminder

Hi Imar,

Thanks for that. I have just skim re-read chapter 15 and have seen where you are going with the control caching and API caching. These comments make perfect sense. I had forgotten these points but please forgive me since I am still learning? (I am getting there, honestly!)

That said, your tuition does not quite suit my situation since it is not a data control or a file that I am trying to cache. It is just a plain aspx page with text and pictures and I cannot see any properties that I can set against these controls to implement control caching that would cache the pictures and text in a page and would then leave the masterpage in a dynamic mode.

Am I barking up the wrong tree Imar or is there a way to do this?

Cheers,

Ian Ryder.
Reply With Quote
  #6 (permalink)  
Old May 24th, 2012, 08:23 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

If your pages contain mostly static text, there's not much point in caching the entire page as there's not much benefit (processing a plain ASPX page is a relatively quick operation). Output caching is primarily interesing for pages that are viewed often, are not user specific and display data that is relatively hard to get (when it requires database access for example).

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old May 24th, 2012, 09:17 AM
Authorized User
Points: 257, Level: 5
Points: 257, Level: 5 Points: 257, Level: 5 Points: 257, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Location: Healing, UK
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Thanks Imar,

That's interesting and helps a lot when thinking about when to use caching especially when accessing a database.

One thing that I did learn yesterday (browsing the internet) and which does suit my current situation is using partial page caching. That is to say, I design my static information, being pictures and text etc, in a Web User Control which can accept an output cache argument but is then independent of the rest of the page that the control is added to. i.e the MasterPage is not cached and therefore stays dynamic to show my LoginView information correctly.

I have realised that this could be quite a bit of extra work to achieve the desired results but would your experience suggest any reason NOT to use this approach based on your last comments?

Cheers,

Ian.
Reply With Quote
  #8 (permalink)  
Old May 25th, 2012, 02:36 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Ian,

Yes, that makes perfect sense. Should have recommended that as an option earlier....Still, you'll only see real benefits if the content of the UC is hard to create. With static text, I doubt you'll be able to measure the performance increase.

You may want to read the section "When to optimize" and especially the part that says " about 97% of the time: premature optimization is the root of all evil" on this Wiki article: http://en.wikipedia.org/wiki/Program_optimization ;-)

That's not to say that caching isn't necessary, but you should measure first and then determine if you really need it before it affects your design.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OutputCache Problem walbalooshi BOOK: Professional ASP.NET 4 : in C# and VB 0 October 27th, 2010 11:03 AM
Displaying the Photo Album in a LoginView? RobinB3 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 9 April 15th, 2010 03:22 AM
LoginView iceman90289 ASP.NET 3.5 Basics 8 March 4th, 2009 05:33 PM
scope issue with LoginView iceman90289 ASP.NET 3.5 Basics 3 February 5th, 2009 08:57 PM
Trying to use a LoginView within a Repeater BSpeerTX ASP.NET 2.0 Basics 2 April 23rd, 2007 10:57 AM



All times are GMT -4. The time now is 09:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.