Caching and PageLoad event

G

Guest

Hi,

If I turn on the caching for a page with the following directive:

<%@ OutputCache Duration="600" VaryByParam="None" %>

will the Page_Load event always fire? If I have some static data that are
retrieved from the database and would like to avoid retrieving it every time
the page is accessed, could I use the above directive and include the
following statement in the Page_Load event?

if (!this.Page.IsPostBack)

Or is there a better way for doing this?

Thanks.
Mike
 
J

Joyjit Mukherjee

Hi,

No, your Page_Load will be cached first when the first user accessess the
page, and then any subsequent request upto 600 seconds will be served from
the cache.

For static objects, store them in the cache object in the initial Page_Load
i.e., in !IsPostBack to avoid loading it for a second time.

Regards
Joyjit
 
E

Egbert Nierop \(MVP for IIS\)

Mike said:
Hi,

If I turn on the caching for a page with the following directive:

<%@ OutputCache Duration="600" VaryByParam="None" %>

will the Page_Load event always fire? If I have some static data that are
retrieved from the database and would like to avoid retrieving it every time
the page is accessed, could I use the above directive and include the
following statement in the Page_Load event?

if (!this.Page.IsPostBack)

Or is there a better way for doing this?

You can set the cache options programmable Response.Cache.... instead of
using page directives.

But as soon as caching is -on- the page is served as *static* data, so
page_Load does not trigger.
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top