fix composite cache keys and remove setByHttp
This commit is contained in:
parent
43413fe75c
commit
92cd204b31
10 changed files with 78 additions and 71 deletions
|
|
@ -165,30 +165,6 @@ sub exportGetUrlAsPath {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getCache ( $calledAsWebMethod )
|
||||
|
||||
Overrides the base method to handle Snippet specific caching.
|
||||
|
||||
=head3 $calledAsWebMethod
|
||||
|
||||
If this is true, then change the cache key.
|
||||
|
||||
=cut
|
||||
|
||||
sub getCache {
|
||||
my $self = shift;
|
||||
my $calledAsWebMethod = shift;
|
||||
my $session = $self->session;
|
||||
my $cacheKey = "view_".$calledAsWebMethod.'_'.$self->getId;
|
||||
if ($session->env->sslRequest) {
|
||||
$cacheKey .= '_ssl';
|
||||
}
|
||||
my $cache = WebGUI::Cache->new($session, $cacheKey);
|
||||
return $cache;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getToolbar ( )
|
||||
|
||||
Returns a toolbar with a set of icons that hyperlink to functions that delete, edit, promote, demote, cut, and copy.
|
||||
|
|
|
|||
|
|
@ -270,8 +270,8 @@ override purgeCache => sub {
|
|||
my $self = shift;
|
||||
my $cache = $self->session->cache;
|
||||
eval {
|
||||
$cache->delete([$self->proxiedUrl,"URL"]);
|
||||
$cache->delete([$self->proxiedUrl,"HEADER"]);
|
||||
$cache->delete($self->proxiedUrl."_URL");
|
||||
$cache->delete($self->proxiedUrl."_HEADER");
|
||||
};
|
||||
super();
|
||||
};
|
||||
|
|
@ -317,8 +317,8 @@ sub view {
|
|||
my $cache = $self->session->cache;
|
||||
if ($requestMethod =~ /^GET$/i) {
|
||||
eval {
|
||||
$var{header} = $cache->get([$proxiedUrl,'HEADER']);
|
||||
$var{content} = $cache->get([$proxiedUrl,"URL"]);
|
||||
$var{header} = $cache->get($proxiedUrl.'_HEADER');
|
||||
$var{content} = $cache->get($proxiedUrl."_URL");
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -460,8 +460,8 @@ sub view {
|
|||
}
|
||||
unless ($self->cacheTimeout <= 10) {
|
||||
eval{
|
||||
$cache->set([$proxiedUrl,'URL'], $var{content}, $self->cacheTimeout);
|
||||
$cache->set([$proxiedUrl,'HEADER'], $var{header}, $self->cacheTimeout);
|
||||
$cache->set($proxiedUrl.'URL', $var{content}, $self->cacheTimeout);
|
||||
$cache->set($proxiedUrl.'HEADER', $var{header}, $self->cacheTimeout);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,23 +115,36 @@ Combines all feeds into a single XML::FeedPP object.
|
|||
sub generateFeed {
|
||||
my $self = shift;
|
||||
my $limit = shift || $self->maxHeadlines;
|
||||
my $session = $self->session;
|
||||
my ( $log, $cache ) = $session->quick(qw( log cache ));
|
||||
my $feed = XML::FeedPP::Atom->new();
|
||||
my $log = $self->session->log;
|
||||
|
||||
# build one feed out of many
|
||||
my $newlyCached = 0;
|
||||
my $cache = $self->session->cache;
|
||||
foreach my $url (split(/\s+/, $self->rssUrl)) {
|
||||
$log->info("Processing FEED: ".$url);
|
||||
$url =~ s/^feed:/http:/;
|
||||
if ($self->processMacroInRssUrl) {
|
||||
WebGUI::Macro::process($self->session, \$url);
|
||||
}
|
||||
my $value = eval{$cache->get($url)};
|
||||
unless ($value) {
|
||||
$value = eval{$cache->setByHttp($url, $self->cacheTimeout)};
|
||||
$newlyCached = 1;
|
||||
}
|
||||
|
||||
my $value = $cache->compute( $url, sub {
|
||||
my $ua = LWP::UserAgent->new(
|
||||
env_proxy => 1,
|
||||
agent => "WebGUI/" . $WebGUI::VERSION,
|
||||
timeout => 30,
|
||||
);
|
||||
|
||||
my $r = $ua->get( $url );
|
||||
if ( $r->is_error ) {
|
||||
$session->log->warn( "Could not get syndicated content from '$url': " . $r->status_line );
|
||||
}
|
||||
else {
|
||||
$newlyCached = 1;
|
||||
return $r->decoded_content;
|
||||
}
|
||||
}, $self->cacheTimeout );
|
||||
|
||||
# if the content can be downgraded, it is either valid latin1 or didn't have
|
||||
# an HTTP Content-Encoding header. In the second case, XML::FeedPP will take
|
||||
# care of any encoding specified in the XML prolog
|
||||
|
|
@ -142,7 +155,7 @@ sub generateFeed {
|
|||
$feed->merge_item($singleFeed);
|
||||
};
|
||||
if ($@) {
|
||||
$log->error("Syndicated Content asset (".$self->getId.") has a bad feed URL (".$url."). Failed with ".$@);
|
||||
$log->warn("Syndicated Content asset (".$self->getId.") has a bad feed URL (".$url."). Failed with ".$@);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +172,7 @@ sub generateFeed {
|
|||
}
|
||||
}
|
||||
|
||||
my %seen = {};
|
||||
my %seen = ();
|
||||
my @items = $feed->get_item;
|
||||
$feed->clear_item;
|
||||
ITEM: foreach my $item (@items) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue