@@ -, +, @@ --- C4/XSLT.pm | 9 ++++++++- t/db_dependent/XSLT.t | 18 +++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) --- a/C4/XSLT.pm +++ a/C4/XSLT.pm @@ -30,6 +30,7 @@ use C4::Biblio; use C4::Circulation; use C4::Reserves; use Koha::AuthorisedValues; +use Koha::Caches; use Koha::ItemTypes; use Koha::XSLT_Handler; use Koha::Libraries; @@ -414,8 +415,13 @@ sub CustomXSLTExportList { my $opac = shift; # opac (1) vs intranet (0) return [] if $opac && C4::Context->preference('OpacExportOptions') !~ /custom/; - my @tabFiles; + # Check the cache first + my $cache = Koha::Caches->get_instance; + my $key = $opac ? 'CustomXSLTExportListOPAC' : 'CustomXSLTExportListIntra'; + my $cached_val = $cache->get_from_cache($key); + return $cached_val if $cached_val; + my @tabFiles; my $dir = C4::Context->config( $opac ? 'opachtdocs' : 'intrahtdocs') . '/' . C4::Context->preference( $opac ? "opacthemes" : "template") . '/' . C4::Languages::getlanguage() . @@ -449,6 +455,7 @@ sub CustomXSLTExportList { push @tabFiles, \%row; } } + $cache->set_in_cache( $key, [ @tabFiles ] ); return \@tabFiles; } --- a/t/db_dependent/XSLT.t +++ a/t/db_dependent/XSLT.t @@ -3,22 +3,26 @@ use Test::More tests => 2; use t::lib::Mocks; use C4::XSLT; +use Koha::Caches; use Koha::Database; our $schema = Koha::Database->new->schema; +our $cache = Koha::Caches->get_instance; # Here we go $schema->storage->txn_begin; -subtest 'CustomXSLTExportList: Check export options' => sub { - plan tests => 2; +subtest 'CustomXSLTExportList: Caching' => sub { + plan tests => 1; t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); - my $list = C4::XSLT::CustomXSLTExportList(1); - is( @$list>0, 1, 'We expect at least one result: simple export' ); - t::lib::Mocks::mock_preference('OpacExportOptions', 'dc'); + $cache->clear_from_cache('CustomXSLTExportListOPAC'); + my $list = C4::XSLT::CustomXSLTExportList(1); + push @$list, { nonsense => 1 }; + $cache->set_in_cache( 'CustomXSLTExportListOPAC', $list ); + my $n = @$list; $list = C4::XSLT::CustomXSLTExportList(1); - is( @$list, 0, 'We expect an empty list now' ); + is( @$list, $n, 'This list comes from the cache and that is fine' ); + $cache->clear_from_cache('CustomXSLTExportListOPAC'); }; - subtest 'buildKohaItemsNamespace status tests' => sub { plan tests => 13; my $item = $builder->build_sample_item({}); --