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

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

Return to bug 11998