Lines 370-375
sub new {
Link Here
|
370 |
$self->{"activeuser"} = undef; # current active user |
370 |
$self->{"activeuser"} = undef; # current active user |
371 |
$self->{"shelves"} = undef; |
371 |
$self->{"shelves"} = undef; |
372 |
$self->{tz} = undef; # local timezone object |
372 |
$self->{tz} = undef; # local timezone object |
|
|
373 |
$self->{sysprefs} = {}; |
373 |
|
374 |
|
374 |
bless $self, $class; |
375 |
bless $self, $class; |
375 |
$self->{db_driver} = db_scheme2dbi($self->config('db_scheme')); # cache database driver |
376 |
$self->{db_driver} = db_scheme2dbi($self->config('db_scheme')); # cache database driver |
Lines 505-511
with this method.
Link Here
|
505 |
=cut |
506 |
=cut |
506 |
|
507 |
|
507 |
my $syspref_cache = Koha::Cache->get_instance(); |
508 |
my $syspref_cache = Koha::Cache->get_instance(); |
508 |
my %syspref_L1_cache; |
|
|
509 |
my $use_syspref_cache = 1; |
509 |
my $use_syspref_cache = 1; |
510 |
sub preference { |
510 |
sub preference { |
511 |
my $self = shift; |
511 |
my $self = shift; |
Lines 513-522
sub preference {
Link Here
|
513 |
|
513 |
|
514 |
$var = lc $var; |
514 |
$var = lc $var; |
515 |
|
515 |
|
516 |
# Return the value if the var has already been accessed |
516 |
$self = $context unless ref $self; |
517 |
if ($use_syspref_cache && exists $syspref_L1_cache{$var}) { |
517 |
|
518 |
return $syspref_L1_cache{$var}; |
518 |
return $self->{sysprefs}{$var} if $use_syspref_cache && $self && exists $self->{sysprefs}{$var}; |
519 |
} |
|
|
520 |
|
519 |
|
521 |
my $cached_var = $use_syspref_cache |
520 |
my $cached_var = $use_syspref_cache |
522 |
? $syspref_cache->get_from_cache("syspref_$var") |
521 |
? $syspref_cache->get_from_cache("syspref_$var") |
Lines 526-540
sub preference {
Link Here
|
526 |
my $value; |
525 |
my $value; |
527 |
if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) { |
526 |
if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) { |
528 |
$value = $ENV{"OVERRIDE_SYSPREF_$var"}; |
527 |
$value = $ENV{"OVERRIDE_SYSPREF_$var"}; |
529 |
} else { |
528 |
} elsif ( my $syspref = Koha::Config::SysPrefs->find( $var ) ) { |
530 |
my $syspref; |
529 |
$value = $syspref->value(); |
531 |
eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) }; |
|
|
532 |
$value = $syspref ? $syspref->value() : undef; |
533 |
} |
530 |
} |
534 |
|
531 |
|
535 |
if ( $use_syspref_cache ) { |
532 |
if ( $use_syspref_cache ) { |
536 |
$syspref_cache->set_in_cache("syspref_$var", $value); |
533 |
$syspref_cache->set_in_cache("syspref_$var", $value); |
537 |
$syspref_L1_cache{$var} = $value; |
534 |
$self->{sysprefs}{$var} = $value if $self; |
538 |
} |
535 |
} |
539 |
return $value; |
536 |
return $value; |
540 |
} |
537 |
} |
Lines 588-600
will not be seen by this process.
Link Here
|
588 |
=cut |
585 |
=cut |
589 |
|
586 |
|
590 |
sub clear_syspref_cache { |
587 |
sub clear_syspref_cache { |
|
|
588 |
my ($self) = @_; |
589 |
|
590 |
$self = $context unless ref $self; |
591 |
|
591 |
return unless $use_syspref_cache; |
592 |
return unless $use_syspref_cache; |
592 |
$syspref_cache->flush_all; |
|
|
593 |
clear_syspref_L1_cache() |
594 |
} |
595 |
|
593 |
|
596 |
sub clear_syspref_L1_cache { |
594 |
$syspref_cache->flush_all; |
597 |
%syspref_L1_cache = (); |
595 |
$self->{sysprefs} = {} if $self; |
598 |
} |
596 |
} |
599 |
|
597 |
|
600 |
=head2 set_preference |
598 |
=head2 set_preference |
Lines 613-618
sub set_preference {
Link Here
|
613 |
|
611 |
|
614 |
$variable = lc $variable; |
612 |
$variable = lc $variable; |
615 |
|
613 |
|
|
|
614 |
$self = $context unless ref $self; |
615 |
|
616 |
my $syspref = Koha::Config::SysPrefs->find($variable); |
616 |
my $syspref = Koha::Config::SysPrefs->find($variable); |
617 |
$type = |
617 |
$type = |
618 |
$type ? $type |
618 |
$type ? $type |
Lines 647-653
sub set_preference {
Link Here
|
647 |
|
647 |
|
648 |
if ( $use_syspref_cache ) { |
648 |
if ( $use_syspref_cache ) { |
649 |
$syspref_cache->set_in_cache( "syspref_$variable", $value ); |
649 |
$syspref_cache->set_in_cache( "syspref_$variable", $value ); |
650 |
$syspref_L1_cache{$variable} = $value; |
650 |
$self->{sysprefs}{$variable} = $value if $self; |
651 |
} |
651 |
} |
652 |
|
652 |
|
653 |
return $syspref; |
653 |
return $syspref; |
Lines 666-675
was no syspref of the name.
Link Here
|
666 |
sub delete_preference { |
666 |
sub delete_preference { |
667 |
my ( $self, $var ) = @_; |
667 |
my ( $self, $var ) = @_; |
668 |
|
668 |
|
|
|
669 |
$self = $context unless ref $self; |
670 |
|
669 |
if ( Koha::Config::SysPrefs->find( $var )->delete ) { |
671 |
if ( Koha::Config::SysPrefs->find( $var )->delete ) { |
670 |
if ( $use_syspref_cache ) { |
672 |
if ( $use_syspref_cache ) { |
671 |
$syspref_cache->clear_from_cache("syspref_$var"); |
673 |
$syspref_cache->clear_from_cache("syspref_$var"); |
672 |
delete $syspref_L1_cache{$var}; |
674 |
delete $self->{sysprefs}{$var} if $self; |
673 |
} |
675 |
} |
674 |
|
676 |
|
675 |
return 1; |
677 |
return 1; |