|
Subject:
|
Page caching
|
|
Posted By:
|
cridley
|
Post Date:
|
12/8/2005 6:30:35 AM
|
Hello,
I'm using page caching and was wondering if for this tag:
<%@OutputCache Duration="60" VaryByParam="id" %>
i could store the duration somewhere else, eg the web.config.
|
|
Reply By:
|
exarkuun
|
Reply Date:
|
12/12/2005 12:57:05 PM
|
Hi,
Sure you could and you must, because this is more easy way to change the value on every page.
François
|
|
Reply By:
|
cridley
|
Reply Date:
|
12/14/2005 12:46:42 PM
|
Sorry i meant "could I", not "i could"! I've figured it out now anyway. Here's how if anyone wants to know.
Put this code in the code-behind for the page you want to cache:
int duration = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["CacheDuration"];); Response.Cache.SetExpires(DateTime.Now.AddSeconds(duration )); Response.Cache.SetCacheability(HttpCacheability.Public);
and in the Web.Config put this tag in the AppSettings section:
<add key="CacheDuration" value="60" />
where value is the time in seconds you want the pages to be cached for.
|
|
Reply By:
|
James45
|
Reply Date:
|
1/9/2006 6:58:04 PM
|
Another option that seems usefull is an IIS tool called www.cacheright.com which allows you to write expiration rules based on mime type, file type, and directory without having to write any code.
There is also a neat cache check tool that shows you what files are good candidates for caching: www.port80software.com/support/p80tools
|