Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / SL / DB / Helper / Cache.pm
diff --git a/SL/DB/Helper/Cache.pm b/SL/DB/Helper/Cache.pm
new file mode 100644 (file)
index 0000000..e93b551
--- /dev/null
@@ -0,0 +1,44 @@
+package SL::DB::Helper::Cache;
+
+use strict;
+use warnings;
+
+use Carp;
+
+use parent qw(Rose::DB::Cache);
+
+sub prepare_db {
+  my ($self, $db, $entry) = @_;
+
+  if (!$entry->is_prepared) {
+    # if this a dummy kivitendo dbh, don't try to actually prepare this.
+    if ($db->type =~ /KIVITENDO_EMPTY/) {
+      return;
+    }
+
+    $entry->prepared(1);
+  }
+
+  if (!$db->dbh->ping) {
+    $db->dbh(undef);
+  }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+SL::DB::Helper::Cache - database handle caching for kivitendo
+
+=head1 DESCRIPTION
+
+This class provides database cache handling for kivitendo running
+under FastCGI. It's based on Rose::DBx::Cache::Anywhere.
+
+=head1 METHODS
+
+=head2 prepare_db( I<rose_db>, I<entry> )
+
+Overrides default method to always ping() dbh.