json iconcatalyst iconie icon

Catalyst - Customizing the view to stop IE from caching JSON

Posted in , , , Tue, 25 Jul 2006 15:49:00 GMT

Often times you'll want to customize your response specific to the View being used, e.g. setting extra headers. This can be done directly in your View class by creating a process method. All View base classes have a process method defined in Catalyst::View that gets called at rendering time. By adding a process method in your subclass and redispatching to the parent you can do some preliminary processing.

One use is preventing IE from caching JSON responses by setting the Cache-Control and Pragma HTTP response headers. You can do this in the application's JSON view as follows:

package MyApp::View::JSON;
use strict; use warnings;
use base qw/Catalyst::View::JSON/;

sub process {
  my $self = shift;
  my $c = $_[0];
  $c->res->header( 'Cache-Control' =>
    'no-store, no-cache, must-revalidate,'.
    'post-check=0, pre-check=0, max-age=0'
  );
  $c->res->header( 'Pragma' => 'no-cache' );
  $c->res->header( 'Expires' => 'Thu, 01 Jan 1970 00:00:00 GMT' );
  $self->NEXT::process(@_);
}

1;

Your process method will get called, set it's response headers and then use NEXT to call C::V::JSON's process method.

del.icio.us:Catalyst - Customizing the view to stop IE from caching JSON digg:Catalyst - Customizing the view to stop IE from caching JSON reddit:Catalyst - Customizing the view to stop IE from caching JSON spurl:Catalyst - Customizing the view to stop IE from caching JSON wists:Catalyst - Customizing the view to stop IE from caching JSON simpy:Catalyst - Customizing the view to stop IE from caching JSON newsvine:Catalyst - Customizing the view to stop IE from caching JSON blinklist:Catalyst - Customizing the view to stop IE from caching JSON furl:Catalyst - Customizing the view to stop IE from caching JSON fark:Catalyst - Customizing the view to stop IE from caching JSON blogmarks:Catalyst - Customizing the view to stop IE from caching JSON Y!:Catalyst - Customizing the view to stop IE from caching JSON smarking:Catalyst - Customizing the view to stop IE from caching JSON magnolia:Catalyst - Customizing the view to stop IE from caching JSON segnalo:Catalyst - Customizing the view to stop IE from caching JSON

no comments

Comments

(leave url/email »)

   Comment Markup Help Preview comment