@@ -, +, @@ Koha::CirculationRules::get_effective_rule --- Koha/CirculationRules.pm | 15 +++++++++++++++ admin/smart-rules.pl | 1 + 2 files changed, 16 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 EFFECTIVE_RULE_KEY => 'Koha_CirculationRule_get_effective_rule-'; =head1 NAME @@ -190,6 +191,18 @@ sub get_effective_rule { "Required parameter 'rule_name' missing") unless $rule_name; + my $cache = Koha::Caches->get_instance(); + my $cache_key = EFFECTIVE_RULE_KEY.$rule_name; + foreach ( $branchcode, $categorycode, $itemtype ) { + $cache_key .= '-'.($_ ? $_ : ''); + } + my $cached = $cache->get_from_cache($cache_key); + if ($cached) { + 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 +225,8 @@ sub get_effective_rule { } )->single; + $cache->set_in_cache( $cache_key, $rule->unblessed ) if $rule; + return $rule; } --- a/admin/smart-rules.pl +++ a/admin/smart-rules.pl @@ -69,6 +69,7 @@ my $language = C4::Languages::getlanguage(); my $cache = Koha::Caches->get_instance; $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); +$cache->clear_from_cache( Koha::CirculationRules::EFFECTIVE_RULE_KEY ); if ($op eq 'delete') { my $itemtype = $input->param('itemtype'); --