Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b9d5cb7b

Von Moritz Bunkus vor mehr als 5 Jahren hinzugefügt

  • ID b9d5cb7b49b3394142b257cd0186652e91cb3b5f
  • Vorgänger 526ee243
  • Nachfolger ea4256d8

SL::DB::Cache nach SL::DB::Helper::Cache verschoben

Da es sich nicht um eine Mapping-Klasse einer Tabelle handelt, sollte
sie nicht direkt innerhalb von SL::DB liegen.

Unterschiede anzeigen:

SL/DB.pm
6 6
use Data::Dumper;
7 7
use English qw(-no_match_vars);
8 8
use Rose::DB;
9
use SL::DB::Cache;
9
use SL::DB::Helper::Cache;
10 10
use Scalar::Util qw(blessed);
11 11

  
12 12
use base qw(Rose::DB);
13 13

  
14
__PACKAGE__->db_cache_class('SL::DB::Cache');
14
__PACKAGE__->db_cache_class('SL::DB::Helper::Cache');
15 15
__PACKAGE__->use_private_registry;
16 16

  
17 17
my (%_db_registered);
SL/DB/Cache.pm
1
package SL::DB::Cache;
2

  
3
use strict;
4
use warnings;
5

  
6
use Carp;
7

  
8
use parent qw(Rose::DB::Cache);
9

  
10
sub prepare_db {
11
  my ($self, $db, $entry) = @_;
12

  
13
  if (!$entry->is_prepared) {
14
    # if this a dummy kivitendo dbh, don't try to actually prepare this.
15
    if ($db->type =~ /KIVITENDO_EMPTY/) {
16
      return;
17
    }
18

  
19
    $entry->prepared(1);
20
  }
21

  
22
  if (!$db->dbh->ping) {
23
    $db->dbh(undef);
24
  }
25
}
26

  
27
1;
28

  
29
__END__
30

  
31
=head1 NAME
32

  
33
SL::DB::Cache - database handle caching for kivitendo
34

  
35
=head1 DESCRIPTION
36

  
37
This class provides database cache handling for kivitendo running
38
under FastCGI. It's based on Rose::DBx::Cache::Anywhere.
39

  
40
=head1 METHODS
41

  
42
=head2 prepare_db( I<rose_db>, I<entry> )
43

  
44
Overrides default method to always ping() dbh.
SL/DB/Helper/Cache.pm
1
package SL::DB::Helper::Cache;
2

  
3
use strict;
4
use warnings;
5

  
6
use Carp;
7

  
8
use parent qw(Rose::DB::Cache);
9

  
10
sub prepare_db {
11
  my ($self, $db, $entry) = @_;
12

  
13
  if (!$entry->is_prepared) {
14
    # if this a dummy kivitendo dbh, don't try to actually prepare this.
15
    if ($db->type =~ /KIVITENDO_EMPTY/) {
16
      return;
17
    }
18

  
19
    $entry->prepared(1);
20
  }
21

  
22
  if (!$db->dbh->ping) {
23
    $db->dbh(undef);
24
  }
25
}
26

  
27
1;
28

  
29
__END__
30

  
31
=head1 NAME
32

  
33
SL::DB::Helper::Cache - database handle caching for kivitendo
34

  
35
=head1 DESCRIPTION
36

  
37
This class provides database cache handling for kivitendo running
38
under FastCGI. It's based on Rose::DBx::Cache::Anywhere.
39

  
40
=head1 METHODS
41

  
42
=head2 prepare_db( I<rose_db>, I<entry> )
43

  
44
Overrides default method to always ping() dbh.

Auch abrufbar als: Unified diff