Skip to content

Instantly share code, notes, and snippets.

@perlDreamer
Created October 20, 2009 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlDreamer/214565 to your computer and use it in GitHub Desktop.
Save perlDreamer/214565 to your computer and use it in GitHub Desktop.
diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm
index 9e992a8..f687aba 100644
--- a/lib/WebGUI/Asset.pm
+++ b/lib/WebGUI/Asset.pm
@@ -828,6 +828,26 @@ sub getAdminConsole {
#-------------------------------------------------------------------
+=head2 getCache ( )
+
+Returns a cache object specific to this asset, and whether or not the request is in SSL mode.
+
+=cut
+
+sub getCache {
+ my $self = shift;
+ my $session = $self->session;
+ my $cacheKey = "view_".$self->getId;
+ if ($session->env->sslRequest) {
+ $cacheKey .= '_ssl';
+ }
+ my $cache = WebGUI::Cache->new($session, $cacheKey);
+ return $cache;
+}
+
+
+#-------------------------------------------------------------------
+
=head2 getContainer ( )
Returns a reference to the container asset. If this asset is a container it returns a reference to itself. If this asset is not attached to a container it returns its parent.
diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm
index 5d89220..6ffaf9b 100644
--- a/lib/WebGUI/Asset/File.pm
+++ b/lib/WebGUI/Asset/File.pm
@@ -608,7 +608,8 @@ Generate the view method for the Asset, and handle caching.
sub view {
my $self = shift;
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
- my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get;
+ my $cache = $self->getCache;
+ my $out = $cache->get if defined $cache;
return $out if $out;
}
my %var = %{$self->get};
diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm
index c0d705a..8cbe945 100644
--- a/lib/WebGUI/Asset/File/Image.pm
+++ b/lib/WebGUI/Asset/File/Image.pm
@@ -223,7 +223,8 @@ Renders this asset.
sub view {
my $self = shift;
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
- my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get;
+ my $cache = $self->getCache;
+ my $out = $cache->get if defined $cache;
return $out if $out;
}
my %var = %{$self->get};
diff --git a/lib/WebGUI/Asset/File/ZipArchive.pm b/lib/WebGUI/Asset/File/ZipArchive.pm
index 7a11d48..82dbd2f 100644
--- a/lib/WebGUI/Asset/File/ZipArchive.pm
+++ b/lib/WebGUI/Asset/File/ZipArchive.pm
@@ -221,7 +221,8 @@ used to show the file to administrators.
sub view {
my $self = shift;
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
- my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get;
+ my $cache = $self->getCache;
+ my $out = $cache->get if defined $cache;
return $out if $out;
}
my %var = %{$self->get};
diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm
index 097d7d1..cf338db 100644
--- a/lib/WebGUI/Asset/Sku/Product.pm
+++ b/lib/WebGUI/Asset/Sku/Product.pm
@@ -1681,8 +1681,9 @@ sub view {
my $error = shift;
my $session = $self->session;
if (!$session->var->isAdminOn && $self->get("cacheTimeout") > 10){
- my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get;
- return $out if $out;
+ my $cache = $self->getCache;
+ my $out = $cache->get if defined $cache;
+ return $out if $out;
}
my (%data, $segment, %var, @featureloop, @benefitloop, @specificationloop, @accessoryloop, @relatedloop);
tie %data, 'Tie::CPHash';
diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm
index 6ff5d2c..f93698d 100644
--- a/lib/WebGUI/Asset/Snippet.pm
+++ b/lib/WebGUI/Asset/Snippet.pm
@@ -279,7 +279,8 @@ sub view {
|| $self->get("cacheTimeout") <= 10
|| ($versionTag && $versionTag->getId eq $self->get("tagId"));
unless ($noCache) {
- my $out = WebGUI::Cache->new($session,"view_".$calledAsWebMethod."_".$self->getId)->get;
+ my $cache = $self->getCache;
+ my $out = $cache->get if defined $cache;
return $out if $out;
}
my $output = $self->get('usePacked')
diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm
index 285d4c3..512c50c 100644
--- a/lib/WebGUI/Asset/Wobject/Article.pm
+++ b/lib/WebGUI/Asset/Wobject/Article.pm
@@ -350,7 +350,8 @@ sub view {
my $self = shift;
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10 && !$self->session->form->process("overrideTemplateId") &&
!$self->session->form->process($self->paginateVar) && !$self->session->form->process("makePrintable")) {
- my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get;
+ my $cache = $self->getCache;
+ my $out = $cache->get if defined $cache;
return $out if $out;
}
my %var;
diff --git a/lib/WebGUI/Asset/Wobject/Layout.pm b/lib/WebGUI/Asset/Wobject/Layout.pm
index 9ebdf73..f93bc1c 100644
--- a/lib/WebGUI/Asset/Wobject/Layout.pm
+++ b/lib/WebGUI/Asset/Wobject/Layout.pm
@@ -409,12 +409,8 @@ sub www_view {
) {
my $check = $self->checkView;
return $check if (defined $check);
- my $cacheKey = "view_".$self->getId;
- if ($session->env->sslRequest) {
- $cacheKey .= '_ssl';
- }
- my $cache = WebGUI::Cache->new($session, $cacheKey);
- my $out = $cache->get if defined $cache;
+ my $cache = $self->getCache;
+ my $out = $cache->get if defined $cache;
unless ($out) {
$self->prepareView;
$session->stow->set("cacheFixOverride", 1);
diff --git a/lib/WebGUI/Asset/Wobject/MultiSearch.pm b/lib/WebGUI/Asset/Wobject/MultiSearch.pm
index 15e9a7d..c636197 100644
--- a/lib/WebGUI/Asset/Wobject/MultiSearch.pm
+++ b/lib/WebGUI/Asset/Wobject/MultiSearch.pm
@@ -130,7 +130,8 @@ to be displayed within the page style
sub view {
my $self = shift;
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
- my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get;
+ my $cache = $self->getCache;
+ my $out = $cache->get if defined $cache;
return $out if $out;
}
my $i18n = WebGUI::International->new($self->session, 'Asset_MultiSearch');
diff --git a/lib/WebGUI/Asset/Wobject/SQLReport.pm b/lib/WebGUI/Asset/Wobject/SQLReport.pm
index 73e0528..dbb98a0 100644
--- a/lib/WebGUI/Asset/Wobject/SQLReport.pm
+++ b/lib/WebGUI/Asset/Wobject/SQLReport.pm
@@ -534,7 +534,8 @@ if the user is not in Admin Mode.
sub view {
my $self = shift;
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
- my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get;
+ my $cache = $self->getCache;
+ my $out = $cache->get if defined $cache;
return $out if $out;
}
# Initiate an empty debug loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment