--- ResolverResolver.pm.basic	2009-10-22 16:52:55.000000000 -0400
+++ ResolverResolver.pm	2009-10-22 16:56:42.000000000 -0400
@@ -62,11 +62,32 @@
 # This is the client class, used for connecting to open-ils.storage
 use OpenSRF::AppSession;
 
+# This is an extension of Error.pm that supplies some error types to throw
+use OpenSRF::EX qw(:try);
+
+# This is a helper class for querying the OpenSRF Settings application ...
+use OpenSRF::Utils::SettingsClient;
+
 # ... and here we have the built in logging helper ...
 use OpenSRF::Utils::Logger qw($logger);
 
+# ... and this manages cached results for us ...
+use OpenSRF::Utils::Cache;
+
+my $prefix = "open-ils.resolver_"; # Prefix for caching values
+my $cache;
+my $cache_timeout;
+
 our ($ua, $parser);
 
+
+sub initialize {
+	$cache = OpenSRF::Utils::Cache->new('global');
+	my $sclient = OpenSRF::Utils::SettingsClient->new();
+	$cache_timeout = $sclient->config_value(
+			"apps", "open-ils.resolver", "app_settings", "cache_timeout" ) || 300;
+}
+
 sub child_init {
 	# We need a User Agent to speak to the SFX beast
 	$ua = new LWP::UserAgent;
@@ -82,6 +103,9 @@
 	my $id_type = shift; # keep it simple for now, either 'issn' or 'isbn'
 	my $id_value = shift; # the normalized ISSN or ISBN
 
+	# We'll use this in our cache key
+	my $method = "open-ils.resolver.resolve_holdings";
+
 	# For now we'll pass the argument with a hard-coded default
         # Should pull these specifics from the database as part of initialize()
 	my $url_base = shift || 'http://sfx.scholarsportal.info/laurentian';
@@ -98,6 +122,16 @@
 		$url_args .= "&rft.isbn=$id_value";
 	}
 	
+	my $ckey = $prefix . $method . $url_base . $id_type . $id_value;
+
+	# Check the cache to see if we've already looked this up
+	# If we have, shortcut our return value
+	my $result = $cache->get_cache($ckey) || undef;
+	if ($result) {
+		$logger->info("Resolver found a cache hit");	
+		return $result;
+	}
+
 	# Otherwise, let's go and grab the info from the SFX server
 	my $req = HTTP::Request->new('GET', "$url_base$url_args");
 
@@ -120,6 +154,9 @@
 		push @sfx_result, {public_name => $public_name, coverage => $target_coverage, embargo => $target_embargo, url => $target_url};
 	}
 
+	# Stuff this into the cache
+	$cache->put_cache($ckey, \@sfx_result, $cache_timeout);
+	
 	return \@sfx_result;
 }
 
@@ -150,4 +187,6 @@
 		}
 );
 
+# Add methods to clear cache for specific lookups?
+
 1;
