]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
cache Web responses in Webfinger library
authorEvan Prodromou <evan@status.net>
Fri, 26 Feb 2010 02:07:24 +0000 (21:07 -0500)
committerEvan Prodromou <evan@status.net>
Fri, 26 Feb 2010 02:07:24 +0000 (21:07 -0500)
plugins/OStatus/lib/webfinger.php

index 8d70403102b639040c72a9c3fb638d8ce7aa42cd..4b777c9a0acaed8a344fc9ac68a80bd0de243d53 100644 (file)
@@ -81,11 +81,14 @@ class Webfinger
     function getServiceLinks($domain)
     {
         $url = 'http://'. $domain .'/.well-known/host-meta';
+
         $content = $this->fetchURL($url);
+
         if (empty($content)) {
             common_log(LOG_DEBUG, 'Error fetching host-meta');
             return false;
         }
+
         $result = XRD::parse($content);
 
         // Ensure that the host == domain (spec may include signing later)
@@ -119,6 +122,11 @@ class Webfinger
     function fetchURL($url)
     {
         try {
+            $c = Cache::instance();
+            $content = $c->get('webfinger:url:'.$url);
+            if ($content !== false) {
+                return $content;
+            }
             $client = new HTTPClient();
             $response = $client->get($url);
         } catch (HTTP_Request2_Exception $e) {
@@ -129,7 +137,11 @@ class Webfinger
             return false;
         }
 
-        return $response->getBody();
+        $body = $response->getBody();
+
+        $c->set('webfinger:url:'.$url, $body);
+
+        return $body;
     }
 
     function applyTemplate($template, $id)