]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15349, repository_cache class added, which can reduce request time significantly.
authordongsheng <dongsheng>
Tue, 8 Jul 2008 05:00:59 +0000 (05:00 +0000)
committerdongsheng <dongsheng>
Tue, 8 Jul 2008 05:00:59 +0000 (05:00 +0000)
repository/boxnet/boxlibphp5.php
repository/curl.class.php
repository/flickr/phpFlickr.php
repository/ws.php

index 01711f80cd432b903b0159a50a8fa344a57e54e3..0aa753505d06bfb0d29af58c45fc540cffd04514 100755 (executable)
@@ -63,7 +63,7 @@ class boxclient {
             }
         }
         if ($useCURL) {
-            $c = new curl($request);
+            $c = new curl(array('cache'=>true));
             $c->setopt(array('CURLOPT_FOLLOWLOCATION'=>true));
             $xml = $c->get($request);
             /*
index 30c207eacb23d7e61a0bff1d0b43b10850926176..5d9a7b58bee8b0329a01468bbe0fc590788b5209 100644 (file)
@@ -37,10 +37,13 @@ class curl {
         }
         $this->debug = false;
         if(!empty($options['cookie'])) {
-            if(is_file($options['cookie'])) {
+            if(file_exists($options['cookie'])) {
                 $this->cookie = $options['cookie'];
             }
         }
+        if(!empty($options['cache'])) {
+            $this->cache = new repository_cache;
+        }
         $this->resetopt();
     }
     public function resetopt(){
@@ -175,6 +178,7 @@ class curl {
         $this->cleanopt();
         // create curl instance
         $curl = curl_init($url);
+        $this->setopt(array('url'=>$url));
         // reset before set options
         curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this,'formatHeader'));
 
@@ -212,8 +216,15 @@ class curl {
             var_dump($this->header);
         }
 
+        if($this->cache && $ret = $this->cache->get($this->options)) {
+            return $ret;
+        } else {
+            $ret  = curl_exec($curl);
+            if($this->cache) {
+                $this->cache->set($this->options, $ret);
+            }
+        }
 
-        $ret  = curl_exec($curl);
         $this->info  = curl_getinfo($curl);
         $this->error = curl_error($curl);
 
index 0dd926c3e71ada46961a7d3f9f173fdefd35276e..e2464e464aed17bcc4a1e3fd76f2786bd556a623 100755 (executable)
@@ -73,7 +73,7 @@ class phpFlickr {
                $this->php_version = explode(".", $this->php_version[0]);
 
         require_once($CFG->dirroot.'/repository/curl.class.php');
-        $this->curl = new curl;
+        $this->curl = new curl(array('cache'=>true));
        }
 
        function enableCache($type, $connection, $cache_expire = 600, $table = 'flickr_cache')
index 3537bddbb3ed9d9d47f72875ae54471308b62201..a2d31214623dc3af4c24d48874936dc51b04b3c6 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 require_once('../config.php');
 require_once('lib.php');
+$CFG->repository_cache_expire = 120;
 $id        = optional_param('id', PARAM_INT);
 $action    = optional_param('action', '', PARAM_RAW);
 if(!$repository = $DB->get_record('repository', array('id'=>$id))) {