From: dongsheng Date: Tue, 8 Jul 2008 05:00:59 +0000 (+0000) Subject: MDL-15349, repository_cache class added, which can reduce request time significantly. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9d8047cb77c4d1c00184c941e5e35259b77b2e98;p=moodle.git MDL-15349, repository_cache class added, which can reduce request time significantly. --- diff --git a/repository/boxnet/boxlibphp5.php b/repository/boxnet/boxlibphp5.php index 01711f80cd..0aa753505d 100755 --- a/repository/boxnet/boxlibphp5.php +++ b/repository/boxnet/boxlibphp5.php @@ -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); /* diff --git a/repository/curl.class.php b/repository/curl.class.php index 30c207eacb..5d9a7b58be 100644 --- a/repository/curl.class.php +++ b/repository/curl.class.php @@ -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); diff --git a/repository/flickr/phpFlickr.php b/repository/flickr/phpFlickr.php index 0dd926c3e7..e2464e464a 100755 --- a/repository/flickr/phpFlickr.php +++ b/repository/flickr/phpFlickr.php @@ -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') diff --git a/repository/ws.php b/repository/ws.php index 3537bddbb3..a2d3121462 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -1,6 +1,7 @@ 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))) {