View | Details | Raw Unified | Return to bug 11998
Collapse All | Expand All

(-)a/C4/Context.pm (-10 / +13 lines)
Lines 534-551 with this method. Link Here
534
534
535
=cut
535
=cut
536
536
537
# FIXME: running this under mod_perl will require a means of
537
my %syspref_cache;
538
# flushing the caching mechanism.
539
540
my %sysprefs;
541
my $use_syspref_cache = 1;
538
my $use_syspref_cache = 1;
542
539
543
sub preference {
540
sub preference {
544
    my $self = shift;
541
    my $self = shift;
545
    my $var  = shift;    # The system preference to return
542
    my $var  = shift;    # The system preference to return
546
543
547
    if ($use_syspref_cache && exists $sysprefs{lc $var}) {
544
    # We cache for 30 seconds, after that sysprefs are expired from the cache.
548
        return $sysprefs{lc $var};
545
    # This is for persistent environments like Plack.
546
    my $now = time;
547
    my $cache_oldest = $now - 30;
548
    if ($use_syspref_cache && exists $syspref_cache{lc $var}) {
549
        # The cache contains an arrayref, first entry is the time it was
550
        # stored, the second is the value.
551
        my $cached_value = $syspref_cache{lc $var};
552
        return $cached_value->[1] if ($cached_value->[0] > $cache_oldest);
549
    }
553
    }
550
554
551
    my $dbh  = C4::Context->dbh or return 0;
555
    my $dbh  = C4::Context->dbh or return 0;
Lines 564-570 sub preference { Link Here
564
        $value = $dbh->selectrow_array( $sql, {}, lc $var );
568
        $value = $dbh->selectrow_array( $sql, {}, lc $var );
565
    }
569
    }
566
570
567
    $sysprefs{lc $var} = $value;
571
    $syspref_cache{lc $var} = [$now, $value];
568
    return $value;
572
    return $value;
569
}
573
}
570
574
Lines 615-621 will not be seen by this process. Link Here
615
=cut
619
=cut
616
620
617
sub clear_syspref_cache {
621
sub clear_syspref_cache {
618
    %sysprefs = ();
622
    %syspref_cache= ();
619
}
623
}
620
624
621
=head2 set_preference
625
=head2 set_preference
Lines 646-652 sub set_preference { Link Here
646
    " );
650
    " );
647
651
648
    if($sth->execute( $var, $value )) {
652
    if($sth->execute( $var, $value )) {
649
        $sysprefs{$var} = $value;
653
        $syspref_cache{$var} = [time, $value];
650
    }
654
    }
651
    $sth->finish;
655
    $sth->finish;
652
}
656
}
653
- 

Return to bug 11998