SL::DB::Part: Cachen von Objekten gefixt Teil 2
authorMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 19 Jun 2014 13:12:49 +0000 (15:12 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 19 Jun 2014 13:13:28 +0000 (15:13 +0200)
get_active_taxkey hat vorher ganz einfach nicht gecachet.

SL/DB/Chart.pm
SL/DB/Manager/Chart.pm

index 7c50b43..40ac530 100644 (file)
@@ -18,14 +18,13 @@ sub get_active_taxkey {
   $date ||= DateTime->today_local;
 
   my $cache = $::request->cache("get_active_taxkey")->{$date} //= {};
-  if ($cache->{$self->id}) {
-    return $cache->{$self->id};
-  }
+  return $cache->{$self->id} if $cache->{$self->id};
 
   require SL::DB::TaxKey;
-  return SL::DB::Manager::TaxKey->get_all(query   => [ and => [ chart_id  => $self->id,
-                                                                startdate => { le => $date } ] ],
-                                          sort_by => "startdate DESC")->[0];
+  return $cache->{$self->id} = SL::DB::Manager::TaxKey->get_all(
+    query   => [ and => [ chart_id  => $self->id,
+                          startdate => { le => $date } ] ],
+    sort_by => "startdate DESC")->[0];
 }
 
 1;
index 81a65b5..f7728ae 100644 (file)
@@ -26,7 +26,7 @@ sub cache_taxkeys {
   my ($self, %params) = @_;
 
   my $date  = $params{date} || DateTime->today;
-  my $cache = $::request->{cache}{chart}{$date} ||= {};
+  my $cache = $::request->cache('::SL::DB::Chart::get_active_taxkey')->{$date} //= {};
 
   require SL::DB::TaxKey;
   my $tks = SL::DB::Manager::TaxKey->get_all;