From e3f61a5f84f438a17ff2cc9d9ed7c8c636cf9c42 Mon Sep 17 00:00:00 2001
From: Julian FIOL <julian.fiol@biblibre.com>
Date: Tue, 30 Jun 2015 14:20:44 +0200
Subject: [PATCH] bug 14476 : Caching C4::XSLT::transformMARCXML4XSLT

This patch is improving the opac-search performances by
caching the results of C4::XSLT::transformMARCXML4XSLT

My tests (with Devel::NYTProf) showed a gain of about
65% on C4::XSLT::transformMARCXML4XSLT and
35% on C4::XSLT::XSLTParse4Display.

The gain of performances is increasing with the numbers
of results.
---
 C4/XSLT.pm | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/C4/XSLT.pm b/C4/XSLT.pm
index 7a94f2c..91e51a6 100644
--- a/C4/XSLT.pm
+++ b/C4/XSLT.pm
@@ -68,7 +68,13 @@ Is only used in this module currently.
 sub transformMARCXML4XSLT {
     my ($biblionumber, $record) = @_;
     my $frameworkcode = GetFrameworkCode($biblionumber) || '';
+    my $cache = Koha::Cache->get_instance();
+    my $cache_key = "transformMARCXML4XSLT-$biblionumber";
+    my $cached = $cache->get_from_cache($cache_key);
+    return $cached if $cached;
+
     my $tagslib = &GetMarcStructure(1,$frameworkcode);
+
     my @fields;
     # FIXME: wish there was a better way to handle exceptions
     eval {
@@ -95,6 +101,7 @@ sub transformMARCXML4XSLT {
             }
         }
     }
+    $cache->set_in_cache( "transformMARCXML4XSLT-$biblionumber", $record, { expiry => 3600 } );
     return $record;
 }
 
-- 
2.4.3