From 0915c6a829b59d9d985034ba029821415d384f69 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Tue, 26 Jun 2012 15:03:37 -0400 Subject: [PATCH] Teach the autosuggest web service to cache suggestions where appropriate Signed-off-by: Mike Rylander --- .../src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm | 44 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm index 7ed9bf7c65..ee577f540a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm @@ -13,6 +13,28 @@ use CGI qw(:all -utf8); use OpenSRF::Utils::JSON; use OpenILS::Utils::CStoreEditor qw/:funcs/; +use OpenSRF::Utils::Logger qw/:level/; +use OpenSRF::Utils::SettingsClient; +use OpenSRF::Utils::Cache; + +my $log = 'OpenSRF::Utils::Logger'; + +my $cache; +my $cache_timeout; +my $parser = XML::LibXML->new(); +my $xslt = XML::LibXSLT->new(); + +sub initialize { + + my $conf = OpenSRF::Utils::SettingsClient->new; + + $cache_timeout = $conf->config_value( + "apps", "open-ils.search", "app_settings", "cache_timeout" ) || 300; + +} +sub child_init { + $cache = OpenSRF::Utils::Cache->new('global'); +} # BEGIN package globals @@ -91,7 +113,23 @@ sub get_suggestions { defined $short_word_length ? int($short_word_length) : undef ); - return $editor->json_query({ + $key = 'oils_AS_' . md5_hex( + $query . + $search_class . + $org_unit . + $css_prefix . + $highlight_min . + $highlight_max . + $normalization . + $limit . + $short_word_length + ); + + $res = $cache->get_cache( $key ); + + return $res if ($res); + + $res = $editor->json_query({ "from" => [ "metabib.suggest_browse_entries", $query, @@ -102,6 +140,10 @@ sub get_suggestions { $normalization ] }); + + $cache->put_cache( $key => $res => $cache_timeout ); + + return $res; } sub suggestions_to_xml { -- 2.11.0