Caching DataGrid Page

J

Janaka

Hi All,

I'm having a problem with Page Output caching on a page that contains a
DataGrid. Basically the page pulls up some data for sales information from
the DB. Some of this has to be calculated on the fly when the request is
made, and so I thought it would be ideal to cache the page for a set amount
of time. I've placed the following at the top of my page: <%@ OutputCache
Duration="160" VaryByParam="None" %>
Now the problem is that this works fine if I am just looking at the
DataGrid, however it also needs to be editable. Once I click on the edit
link on the relevant row the page goes into the EditItemTemplate view and
stay's cached like this for the set period of time! Nothing can be done on
the page until the cache expires.

Is there a way of setting the caching policy to cache only when the DataGrid
is not in edit mode?
 
C

Cowboy \(Gregory A. Beamer\)

Unfortunately, the caching model does not support this. You can "cache" the
data yourself, using a static (Shared VB.NET) method, but you will likely
cache data only, and not the actual grid. If the data is the same across all
sessions, until edited, you can use the Singleton pattern to store the data
and set a cache release time on the Singleton object (hits after this time
force a requery). You can then allow the data to be edited and stored in the
Singleton, as well as updated in the database.

None of this is automagic. You will have to write it.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
J

Janaka

Yeah about the same as what I was thinking. Do you think it would be
possible though to use the VaryByParam setting to vary by what the datagrid
clicks send to the browser?
 
T

Tommy

The following is copied from MSDN. It describe the different ways you
can control caching. It looks like the "VaryByCustom" option can do
what you need.

VaryByCustom
Any text that represents custom output caching requirements. If this
attribute is given a value of browser, the cache is varied by browser
name and major version information. If a custom string is entered, you
must override the HttpApplication.GetVaryByCustomString method in your
application's Global.asax file.


VaryByHeader
A semicolon-separated list of HTTP headers used to vary the output
cache. When this attribute is set to multiple headers, the output
cache contains a different version of the requested document for each
specified header.
Note Setting the VaryByHeader attribute enables caching items in all
HTTP 1.1 caches, not just the ASP.NET cache. This attribute is not
supported for @ OutputCache directives in user controls.


VaryByParam
A semicolon-separated list of strings used to vary the output cache.
By default, these strings correspond to a query string value sent with
GET method attributes, or a parameter sent using the POST method. When
this attribute is set to multiple parameters, the output cache
contains a different version of the requested document for each
specified parameter. Possible values include none, *, and any valid
query string or POST parameter name.
CAUTION This attribute is required when you output cache ASP.NET
pages. It is required for user controls as well unless you have
included a VaryByControl attribute in the control's @ OutputCache
directive. A parser error occurs if you fail to include it. If you do
not want to specify a parameter to vary cached content, set the value
to none. If you want to vary the output cache by all parameter values,
set the attribute to *.


VaryByControl
A semicolon-separated list of strings used to vary a user control's
output cache. These strings represent the ID property values of
ASP.NET server controls declared in the user control. For more
information, see Caching Portions of an ASP.NET Page.
Note This attribute is required in a user control @ OutputCache
directive unless you have included a VaryByParam attribute. This
attribute is not supported for @ OutputCache directives in ASP.NET
pages.

Tommy,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with Caching 2
User Control Caching 1
user control caching 0
Browser Caching Problem 3
Page Caching 1
Leverage browser caching 2
Fragment Caching 0
Page Caching - Warning: Page has Expired 1

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top