diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 5fde8666a..0f11632c7 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -350,7 +350,7 @@ around BUILDARGS => sub { } } - my $properties = eval{$session->cache->get(["asset",$assetId,$revisionDate])}; + my $properties = eval{$session->cache->get("asset".$assetId.$revisionDate)}; unless (exists $properties->{assetId}) { # can we get it from cache? my $sql = "select * from asset"; my $where = " where asset.assetId=?"; @@ -368,7 +368,7 @@ around BUILDARGS => sub { $session->errorHandler->error("Asset $assetId $className $revisionDate is missing properties. Consult your database tables for corruption. "); return undef; } - eval{ $session->cache->set(["asset",$assetId,$revisionDate], $properties, 60*60*24) }; + eval{ $session->cache->set("asset".$assetId.$revisionDate, $properties, 60*60*24) }; } if (defined $properties) { @@ -2369,7 +2369,7 @@ sub purgeCache { $stow->delete('assetLineage'); $stow->delete('assetClass'); $stow->delete('assetRevision'); - eval{$self->session->cache->delete(["asset",$self->getId,$self->get("revisionDate")])}; + eval{$self->session->cache->delete("asset".$self->getId.$self->get("revisionDate"))}; } diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index 78e998c42..3da563f43 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -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. diff --git a/lib/WebGUI/Asset/Wobject/HttpProxy.pm b/lib/WebGUI/Asset/Wobject/HttpProxy.pm index bc4db5bf2..7affd50e9 100644 --- a/lib/WebGUI/Asset/Wobject/HttpProxy.pm +++ b/lib/WebGUI/Asset/Wobject/HttpProxy.pm @@ -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); }; } } diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm index c8efaeb82..b7a2ba715 100644 --- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm +++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm @@ -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) { diff --git a/lib/WebGUI/Cache.pm b/lib/WebGUI/Cache.pm index 723460abb..c4d05149c 100644 --- a/lib/WebGUI/Cache.pm +++ b/lib/WebGUI/Cache.pm @@ -457,16 +457,19 @@ sub setByHttp { if ($debug) { $self->session->log->debug("Called setByHttp() with URL $url."); } - my $userAgent = new LWP::UserAgent; - $userAgent->env_proxy; - $userAgent->agent("WebGUI/".$WebGUI::VERSION); - $userAgent->timeout(30); - my $header = new HTTP::Headers; - my $referer = "http://webgui.http.request/".$self->session->env->get("SERVER_NAME").$self->session->env->get("REQUEST_URI"); - chomp $referer; - $header->referer($referer); - my $request = HTTP::Request->new(GET => $url, $header); - my $response = $userAgent->request($request); + + # Why is this being done? + my $referer = "http://webgui.http.request/".$self->session->env->get("SERVER_NAME").$self->session->env->get("REQUEST_URI"); + chomp $referer; + + my $ua = LWP::UserAgent->new( + env_proxy => 1, + agent => "WebGUI/" . $WebGUI::VERSION, + timeout => 30, + default_headers => HTTP::Headers->new( referer => $referer ), + ); + + my $response = $ua->get( $url ); if ($response->is_error) { $self->session->log->error("$url could not be retrieved."); if ($debug) { diff --git a/lib/WebGUI/Operation/Statistics.pm b/lib/WebGUI/Operation/Statistics.pm index 8e9265837..659ecb458 100644 --- a/lib/WebGUI/Operation/Statistics.pm +++ b/lib/WebGUI/Operation/Statistics.pm @@ -182,13 +182,26 @@ sub www_viewStatistics { return $session->privilege->adminOnly() unless canView($session); my ($output, $data); my $i18n = WebGUI::International->new($session); - my $url = "http://update.webgui.org/latest-version.txt"; + + # Get the latest WebGUI version + my $url = "http://update.webgui.org/latest-version.txt"; my $cache = $session->cache; - my $version = eval{$cache->get($url)}; - if (not defined $version) { - $version = eval{$cache->setByHttp($url, 43200)}; - } - chomp $version; + 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 latest WebGUI version from '$url': " . $r->status_line ); + } + else { + return $r->decoded_content; + } + } ); + $output .= '
| '.$i18n->get(145).': | '.$WebGUI::VERSION.'-'.$WebGUI::STATUS.' |