]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-18848, curl_cache is not specific to repository module any more"
authordongsheng <dongsheng>
Tue, 14 Apr 2009 02:34:38 +0000 (02:34 +0000)
committerdongsheng <dongsheng>
Tue, 14 Apr 2009 02:34:38 +0000 (02:34 +0000)
admin/settings/plugins.php
admin/settings/server.php
lang/en_utf8/admin.php
lib/boxlib.php
lib/filelib.php
lib/flickrlib.php
repository/ws.php
repository/youtube/repository.class.php
version.php

index a8474ed1f766dd41390bcd002aeaa1cd7a2f35e0..b48e54aa033460cf4fe3eaec4569f654901945c5 100644 (file)
@@ -197,7 +197,7 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext))
     $temp->add(new admin_setting_heading('managerepositories', get_string('activerepository', 'repository'), ''));
     $temp->add(new admin_setting_managerepository());
     $temp->add(new admin_setting_heading('managerepositoriescommonheading', get_string('commonsettings', 'admin'), ''));
-    $temp->add(new admin_setting_configtext('repository_cache_expire', get_string('cacheexpire', 'repository'), get_string('configcacheexpire', 'repository'), 120));
+    $temp->add(new admin_setting_configtext('repositorycacheexpire', get_string('cacheexpire', 'repository'), get_string('configcacheexpire', 'repository'), 120));
     $ADMIN->add('repositorysettings', $temp);
     $ADMIN->add('repositorysettings', new admin_externalpage('repositorynew',
         get_string('addplugin', 'repository'), $url, 'moodle/site:config', true),
index da5d81fbf0c02f2943e30b2aa0b26fce0a2cce1e..b4b124a778753ad7855a5dd9b04d48e14c6af8d2 100644 (file)
@@ -257,6 +257,8 @@ $temp->add(new admin_setting_configtext('rcachettl', get_string('rcachettl', 'ad
                                         get_string('configrcachettl', 'admin'), 10));
 $temp->add(new admin_setting_configtext('intcachemax', get_string('intcachemax', 'admin'),
                                         get_string('configintcachemax', 'admin'), 10));
+$temp->add(new admin_setting_configtext('curlcache', get_string('curlcache', 'admin'),
+                                        get_string('configcurlcache', 'admin'), 120, PARAM_INT));
 $temp->add(new admin_setting_configtext('memcachedhosts', get_string('memcachedhosts', 'admin'),
                                         get_string('configmemcachedhosts', 'admin'), ''));
 $temp->add(new admin_setting_configselect('memcachedpconn', get_string('memcachedpconn', 'admin'),
index d441f63e0d1cf93ae91069a01a87bcf19a6a3189..2ec37196f17c0ca24e24397d6b16b8d9b5861e54 100644 (file)
@@ -97,6 +97,7 @@ $string['configcourserequestnotify'] = 'Type username of user to be notified whe
 $string['configcourserequestnotify2'] = 'Users who will be notified when a course is requested. Only users who can approve course requests are listed here.';
 $string['configcoursesperpage'] = 'Enter the number of courses to be display per page in a course listing.';
 $string['configcreatornewroleid'] = 'This role is automatically assigned to creators in new courses they created. This role is not assigned if creator already has needed capabilities in parent context.';
+$string['configcurlcache'] = 'Time-to-live for cURL cache, in seconds.';
 $string['configdbsessions'] = 'If enabled, this setting will use the database to store information about current sessions.  This is especially useful for large/busy sites or sites built on cluster of servers.  For most sites this should probably be left disabled so that the server disk is used instead.  Note that changing this setting now will log out all current users (including you). If you are using MySQL please make sure that \'max_allowed_packet\' in my.cnf (or my.ini) is at least 4M.';
 $string['configdebug'] = 'If you turn this on, then PHP\'s error_reporting will be increased so that more warnings are printed.  This is only useful for developers.';
 $string['configdebugdisplay'] = 'Set to on, the error reporting will go to the HTML page. This is practical, but breaks XHTML, JS, cookies and HTTP headers in general. Set to off, it will send the output to your server logs, allowing better debugging. The PHP setting error_log controls which log this goes to.';
@@ -304,6 +305,7 @@ $string['cronwarning'] = 'The <a href=\"cron.php\">cron.php maintenance script</
 $string['ctyperecommended'] = 'Installing the optional ctype PHP extension is highly recommended in order to improve site performance, particularly if your site is supporting non-latin languages.';
 $string['ctyperequired'] = 'The ctype PHP extension is now required by Moodle, in order to improve site performance and to offer multilingual compatibility.';
 $string['csvdelimiter'] = 'CSV delimiter';
+$string['curlcache'] = 'cURL cache TTL';
 $string['curlrecommended'] = 'Installing the optional cURL library is highly recommended in order to enable Moodle Networking functionality.';
 $string['curlrequired'] = 'The cURL PHP extension is now required by Moodle, in order to commnunicate with Moodle repositories.';
 $string['customcheck'] = 'Other Checks';
index cfe62390eb546e84b23a10fc166c162175e11ee3..74e5ab17b8eb08f322d0e9e81984144156d41a15 100755 (executable)
@@ -29,16 +29,16 @@ class boxclient {
     public function __construct($api_key, $auth_token = '', $debug = false) {
         $this->api_key    = $api_key;
         $this->auth_token = $auth_token;
-        $this->debug = $debug;
+        if (!empty($debug)) {
+            $this->debug = true;
+        } else {
+            $this->debug = false;
+        }
     }
     // Setup for Functions
     function makeRequest($method, $params = array()) {
         $this->_clearErrors();
-        if($this->debug){
-            $c = new curl(array('debug'=>true, 'cache'=>true));
-        } else {
-            $c = new curl(array('debug'=>false, 'cache'=>true));
-        }
+        $c = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository'));
         try {
             if ($method == 'upload'){
                 $request = $this->_box_api_upload_url.'/'.
@@ -91,11 +91,7 @@ class boxclient {
     //              'password'=>'xxx'));
     //
     function getAuthToken($ticket, $username, $password) {
-        if($this->debug){
-            $c = new curl(array('debug'=>true));
-        } else {
-            $c = new curl(array('debug'=>false));
-        }
+        $c = new curl(array('debug'=>$this->debug));
         $c->setopt(array('CURLOPT_FOLLOWLOCATION'=>0));
         $param =  array(
             'login_form1'=>'',
@@ -133,11 +129,7 @@ class boxclient {
         $params['action']     = 'get_account_tree';
         $params['onelevel']   = 1;
         $params['params[]']   = 'nozip';
-        if($this->debug){
-            $c = new curl(array('debug'=>true, 'cache'=>true));
-        } else {
-            $c = new curl(array('debug'=>false, 'cache'=>true));
-        }
+        $c = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository'));
         try {
             $args = array();
             $xml = $c->get($this->_box_api_url, $params);
index 0d83c786455b7b61e411b8e700fbb243ec79efbd..a3f7adf24e41cd3c4bc508e7c8515f2992bd925f 100644 (file)
@@ -1626,7 +1626,11 @@ class curl {
         }
         if (!empty($options['cache'])) {
             if (class_exists('curl_cache')) {
-                $this->cache = new curl_cache;
+                if (!empty($options['module_cache'])) {
+                    $this->cache = new curl_cache($options['module_cache']);
+                } else {
+                    $this->cache = new curl_cache('misc');
+                }
             }
         }
         if (!empty($CFG->proxyhost)) {
@@ -2007,32 +2011,50 @@ class curl {
 /**
  * This class is used by cURL class, use case:
  *
- * $CFG->repository_cache_expire = 120;
- * $c = new curl(array('cache'=>true));
+ * $CFG->repositorycacheexpire = 120;
+ * $CFG->curlcache = 120;
+ *
+ * $c = new curl(array('cache'=>true), 'module_cache'=>'repository');
  * $ret = $c->get('http://www.google.com');
  *
  */
 class curl_cache {
     public $dir = '';
-    function __construct(){
+    /**
+     *
+     * @global $CFG
+     * @param string @module, which module is using curl_cache
+     *
+     */
+    function __construct($module){
         global $CFG;
-        if (!file_exists($CFG->dataroot.'/cache/repository/')) {
-            mkdir($CFG->dataroot.'/cache/repository/', 0777, true);
+        if (!empty($module)) {
+            $this->dir = $CFG->dataroot.'/cache/'.$module.'/';
+        } else {
+            $this->dir = $CFG->dataroot.'/cache/misc/';
         }
-        if(is_dir($CFG->dataroot.'/cache/repository/')) {
-            $this->dir = $CFG->dataroot.'/cache/repository/';
+        if (!file_exists($this->dir)) {
+            mkdir($this->dir, 0700, true);
         }
-        if (empty($CFG->repository_cache_expire)) {
-            $CFG->repository_cache_expire = 120;
+        if ($module == 'repository') {
+            if (empty($CFG->repositorycacheexpire)) {
+                $CFG->repositorycacheexpire = 120;
+            }
+            $this->ttl = $CFG->repositorycacheexpire;
+        } else {
+            if (empty($CFG->curlcache)) {
+                $CFG->curlcache = 120;
+            }
+            $this->ttl = $CFG->curlcache;
         }
     }
     public function get($param){
         global $CFG, $USER;
-        $this->cleanup($CFG->repository_cache_expire);
+        $this->cleanup($this->ttl);
         $filename = 'u'.$USER->id.'_'.md5(serialize($param));
         if(file_exists($this->dir.$filename)) {
             $lasttime = filemtime($this->dir.$filename);
-            if(time()-$lasttime > $CFG->repository_cache_expire)
+            if(time()-$lasttime > $this->ttl)
             {
                 return false;
             } else {
index 8a5c623b8dac6a5717098c3e03b0f990da6daaf2..a5fc7abfa18605b85bdb621294799dc83945d3cd 100755 (executable)
@@ -65,7 +65,7 @@ class phpFlickr {
         //Find the PHP version and store it for future reference
         $this->php_version = explode("-", phpversion());
         $this->php_version = explode(".", $this->php_version[0]);
-        $this->curl = new curl(array('cache'=>true));
+        $this->curl = new curl(array('cache'=>true, 'module_cache'=>'repository'));
     }
 
     function request ($command, $args = array())
index fb6f96d54285c78bf825dc3e11a4bb5fc7f074b0..b252ff098d95da09785eb3b62c488c2a821bf286 100644 (file)
@@ -76,7 +76,7 @@
             break;
 
         case 'ccache':      // Clean cache
-            $cache = new curl_cache;
+            $cache = new curl_cache('repository');
             $cache->refresh();
             $action = 'list';
             break;
index 095d9f42332606a77cfc08a688f4b7d971cc9784..4c19813fce8a76f00400954b9658a81c37dbec2b 100644 (file)
@@ -29,7 +29,7 @@ class repository_youtube extends repository {
     private function _get_collection($keyword, $start, $max, $sort) {
         $list = array();
         $this->feed_url = 'http://gdata.youtube.com/feeds/api/videos?vq=' . urlencode($keyword) . '&format=5&start-index=' . $start . '&max-results=' .$max . '&orderby=' . $sort;
-        $c = new curl(array('cache'=>true));
+        $c = new curl(array('cache'=>true, 'module_cache'=>'repository'));
         $content = $c->get($this->feed_url);
                $xml = simplexml_load_string($content);
         $media = $xml->entry->children('http://search.yahoo.com/mrss/');
index 9bf05077734b41c1da0a4c843eef613fcdbc62c5..6dcdc805a57871f25b10a759932c162050459eba 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2009040600;  // YYYYMMDD   = date of the last version bump
+    $version = 2009040601;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20090414)';  // Human-friendly version name