Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / December 2003

Tip: Looking for answers? Try searching our database.

Caching Individual User Controls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan Bishop - 03 Dec 2003 20:35 GMT
Hi,

I'm hoping that someone can help me with this problem I'm having. I am
developing a website for an airport that is composed entirely of
separate user controls (about 25 in total). There is one ASP.NET page
(Index.aspx), and all of the content is loaded onto the pages from the
database, through each of the user controls.

In one particular control, I make a call to the database to return
flight data for the airport. I would like to cache only this user
control (named "SearchResults.ascx") in order to improve performance.

The problem: When I add the directive <%@ OutputCache Duration="60"
VaryByParams="*" %> to the top of my control, I get an error on the
page saying the "specified cast is not valid". I have also tried
adding the code <PartialCaching(60)> to the meta-data section of the
code behind, but I receive the same error.

Any input would be greatly appreciated. A snippet of the code for the
control is listed below:
******************************************
* User Control Code (SearchResults.ascx)
******************************************
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="SearchResults.ascx.vb" Inherits="gtaaUI.SearchResults"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>

<asp:Repeater id="ArrivingResultsUI" runat="server">
    <HeaderTemplate>
           <!--SNIP-->
    </HeaderTemplate>
    <ItemTemplate>
           <!--SNIP-->
    </ItemTemplate>
    <AlternatingItemTemplate>
           <!--SNIP-->
    </AlternatingItemTemplate>
    <FooterTemplate>
           <!--SNIP-->
    </FooterTemplate>
</asp:Repeater>

<asp:Repeater id="DepartingResultsUI" runat="server">
    <HeaderTemplate>
           <!--SNIP-->
    </HeaderTemplate>
    <ItemTemplate>
           <!--SNIP-->
    </ItemTemplate>
    <AlternatingItemTemplate>
           <!--SNIP-->
    </AlternatingItemTemplate>
    <FooterTemplate>
           <!--SNIP-->
    </FooterTemplate>
</asp:Repeater>

<table runat=server ID="tblError" Border="0" Align="center"
CellSpacing="0" CellPadding="0">
  <!--SNIP-->
</table>
************************************

Many thanks,
-Dan Bishop
Anders Borum - 04 Dec 2003 00:19 GMT
Hello!

You're getting a control of type PartialCachingControl back, when loading a
UserControl with output-caching directives in the header section.

You can't cast a PartialCachingControl to any type of UserControl (including
your own classes derived from UserControl).

Let's see some code, unless the above suggestion helps!

Signature

venlig hilsen / with regards
anders borum
--

Dan Bishop - 04 Dec 2003 14:30 GMT
Hi Anders,

Thank you for your prompt response. Allow me to try and explain
further my configuration/design and the problem at hand:

What I would like to do, is use output caching to save only this one
user control in the server's memory, and I want to vary by a list of
parameters (flight number, airline name, arrivals/departures,
scheduled arrival time, etc.).
The 'problem' is that all of these parameters are obtained from a form
that submits to "Index.aspx" (the form is a separate user control).
The "Index.aspx" page processes these variables and uses them to build
a SQL statement. This SQL statement is run in the database, and the
results are appended to an XML document (in memory). My
"SearchResults.ascx" user control is then responsible for loading all
the flight-related data from the XML and binding it to the two
different asp:Repeater controls.

Given the above structure, I'm not sure if it will be possible to
cache only this user control, since it grabs all of its data from an
XML document... it has no direct relationship to the querystring.

If it is not possible to achieve partial caching given the
above-mentioned design, then a second option would be for me to cache
my Index.aspx page only for certain parameters. For example, I would
like to set it up so that only the page
"http://<servername>/Index.aspx?AIRLINE=AirCanada&FLIGHTNUM=123&TERMINAL=1"
is cached. My whole website is controlled using query string
parameters, so it isn't really feasible for me to use
"VaryByParam='*'". Is there any way to enable caching on only one
specific querystring??

Thanks again for the help.
-Dan Bishop

> Hello!
>
[quoted text clipped - 5 lines]
>
> Let's see some code, unless the above suggestion helps!
Anders Borum - 04 Dec 2003 21:45 GMT
Hello!

> Is there any way to enable caching on only one specific querystring??

Good reply. I'll try another suggestion if this one doesn't work. Yes, you
can cache based on a list of parameters for a specific UserControl.

Not sure if you've been there before, but what you need to do is write a
list of parameters in the VaryByParam directive.

VaryByParam="AIRLINE;FLIGHTNUM;TERMINAL"

This should basically enable the UserControl to cache all combinations of
the above three parameters (regardless of them being QueryString or Form
posts).

And thus the partial caching kicks in - high performance. How about that?

Signature

venlig hilsen / with regards
anders borum
--


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.