Added a better mechanism for calculating when content was last modified for cache headers.

This commit is contained in:
JT Smith 2008-11-06 15:48:31 +00:00
parent 0e18071411
commit f951bbed37
7 changed files with 27 additions and 78 deletions

View file

@ -475,6 +475,11 @@ sub definition {
fieldType=>'hidden',
defaultValue=>'pending'
},
lastModified=>{
noFormPost=>1,
fieldType=>'hidden',
defaultValue=>time(),
},
assetSize=>{
noFormPost=>1,
fieldType=>'hidden',
@ -1450,14 +1455,14 @@ sub getUrl {
Returns the overall modification time of the object and its content in Unix
epoch format, for the purpose of the Last-Modified HTTP header. Override this
for subclasses that contain content that is not solely dependent on the
revisionDate of the asset.
for subclasses that contain content that is not solely lastModified property,
which gets updated every time update() is called.
=cut
sub getContentLastModified {
my $self = shift;
return $self->get("revisionDate");
return $self->get("lastModified");
}
@ -2238,6 +2243,7 @@ to set the keywords for this asset.
sub update {
my $self = shift;
my $properties = shift;
$properties->{lastModified} = time();
# if keywords were specified, then let's set them the right way
if (exists $properties->{keywords}) {

View file

@ -324,12 +324,6 @@ sub formatContent {
return $msg;
}
#-------------------------------------------------------------------
# Too slow to try to find out children, just always assume new data
sub getContentLastModified {
return time();
}
#-------------------------------------------------------------------
sub getAutoCommitWorkflowId {
my $self = shift;

View file

@ -810,12 +810,6 @@ sub duplicate {
return $newAsset;
}
#-------------------------------------------------------------------
# Too slow to try to find out children, just always assume new data
sub getContentLastModified {
return time();
}
#-------------------------------------------------------------------
=head2 getEditTabs

View file

@ -200,6 +200,10 @@ sub generateFeed {
# limit the feed to the maxium number of headlines
$feed->limit_item($self->get('maxHeadlines'));
# mark this asset as updated
$self->update({lastModified=>time});
return $feed;
}
@ -327,68 +331,6 @@ sub view {
$cache->set($out,$self->get("cacheTimeout"));
}
return $out;
my $rssFlavor = shift;
if ($rssFlavor eq "" && !$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get;
return $out if $out;
}
my $maxHeadlines = $self->_getMaxHeadlines;
my @validatedUrls = $self->_getValidatedUrls;
return $self->processTemplate({},$self->get('templateId')) unless (scalar(@validatedUrls));
my $title=$self->get('title');
#We came into this subroutine as
my $rssObject=($rssFlavor) ? XML::RSS::Creator->new(version=>$rssFlavor) : undef;
my %var;
my($item_loop,$rss_feeds)=$self->_get_items(\@validatedUrls, $maxHeadlines);
if (scalar(@$rss_feeds) < 1) {
return $self->processTemplate(\%var,undef,$self->{_viewTemplate});
}
if(@$rss_feeds == 1){
if(@$rss_feeds == 1){
#One feed. Put in the info from the feed.
# Make sure we have a channel to avoid runtime errors
my $channel = $rss_feeds->[0]->{channel};
if ( $channel && ref $channel eq "HASH" ) {
$var{'channel.title'} = $channel->{title} || $title;
$var{'channel.link'} = $channel->{link};
$var{'channel.description'} = $channel->{description};
}
else {
$var{'channel.title'} = $title;
}
}
}
$self->_createRSSURLs(\%var);
$var{item_loop} = $item_loop;
if ($rssObject) {
$self->_constructRSS($rssObject,\%var);
my $rss=$rssObject->as_string;
$self->session->http->setMimeType('text/xml');
#Looks like a kludge, but what this does is put in the proper
#XSLT stylesheet so the RSS doesn't look like total ass.
my $siteURL=$self->session->url->getSiteURL().$self->session->url->gateway();
$rss=~s|<\?xml version="1\.0" encoding="UTF\-8"\?>|<\?xml version="1\.0" encoding="UTF\-8"\?>\n<?xml\-stylesheet type="text/xsl" href="${siteURL}xslt/rss$rssFlavor.xsl"\?>\n|;
return $rss;
} else {
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
WebGUI::Cache->new($self->session,"view_".$self->getId)->set($out,$self->get("cacheTimeout"));
}
return $out;
}
}
#-------------------------------------------------------------------