@@ -, +, @@ Koha::CirculationRules::get_effective_rule --- Koha/CirculationRules.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) --- a/Koha/CirculationRules.pm +++ a/Koha/CirculationRules.pm @@ -26,6 +26,7 @@ use Koha::CirculationRule; use base qw(Koha::Objects); use constant GUESSED_ITEMTYPES_KEY => 'Koha_IssuingRules_last_guess'; +use constant CACHE_NO_CIRCULATION_RULE_VALUE => 'NONE'; =head1 NAME @@ -190,6 +191,21 @@ sub get_effective_rule { "Required parameter 'rule_name' missing") unless $rule_name; + my $cache = Koha::Caches->get_instance(); + my $cache_key = 'CirculationRule_get_effective_rule-'.$rule_name; + foreach ( $branchcode, $categorycode, $itemtype ) { + $cache_key .= '-'.($_ ? $_ : ''); + } + my $cached = $cache->get_from_cache($cache_key); + if ($cached) { + if ( ref $cached eq 'SCALAR' && $cached eq CACHE_NO_CIRCULATION_RULE_VALUE ) { + return undef; + } + my $cr = Koha::CirculationRule->new($cached); + $cr->{_result}->in_storage(1); # Tell it exists in DB + return $cr; + } + for my $v ( $branchcode, $categorycode, $itemtype ) { $v = undef if $v and $v eq '*'; } @@ -212,6 +228,8 @@ sub get_effective_rule { } )->single; + $cache->set_in_cache( $cache_key, $rule ? $rule->unblessed : CACHE_NO_CIRCULATION_RULE_VALUE ); + return $rule; } --