@@ -, +, @@ --- C4/XSLT.pm | 9 ++++++++- t/db_dependent/XSLT.t | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 2 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; @@ -379,8 +380,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() . @@ -414,6 +420,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 @@ -1,11 +1,13 @@ use Modern::Perl; -use Test::More tests => 1; +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; @@ -20,4 +22,17 @@ subtest 'CustomXSLTExportList: Check export options' => sub { $list = C4::XSLT::CustomXSLTExportList(1); is( @$list, 0, 'We expect an empty list now' ); }; + +subtest 'CustomXSLTExportList: Caching' => sub { + plan tests => 1; + t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); + $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, $n, 'This list comes from the cache and that is fine' ); + $cache->clear_from_cache('CustomXSLTExportListOPAC'); +}; $schema->storage->txn_rollback; --