Developer forum

Forum » Development » Deactive browser cache on page level

Deactive browser cache on page level

Kasper Pedersen
Reply

Hi, is there any way to deactivate the browser cache on page level? I see it can be applied globally as a global setting in "/Globalsettings/Settings/Performance/DeactivateBrowserCache".

Are there any public methods available that can be used to perform this operation on page level?

Any help appreciated.


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

That is the only option.

You can easily do it though:

Either create a notification subscriber, i.e. this one:

 [Subscribe(Dynamicweb.Notifications.Standard.Page.OnOutput)]
 public class PageOnOutputObserver : NotificationSubscriber
 {
 public override void OnNotify(string notification, NotificationArgs args)
 {
 if (args == null)
 return;
 var onOutputArgs = (Dynamicweb.Notifications.Standard.Page.OnOutputArgs)args;
 }
 }

and then add some response headers:

response.AddHeader("Cache-Control", "no-cache");
response.AddHeader("Expiresabsolute", DateTime.Now.AddYears(-30).ToString("r"));

Or just do it in the template.

What is your use case?

 
Kasper Pedersen
Reply

Ok, thanks I will try that :)

I'm building a site where i'm implementing CDN and need some pages not to be cached.

 

You must be logged in to post in the forum