mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 08:22:07 +02:00
"MDL-18848, curl_cache is not specific to repository module any more"
This commit is contained in:
parent
ba37af8489
commit
5430f05b37
@ -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),
|
||||
|
@ -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'),
|
||||
|
@ -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';
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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())
|
||||
|
@ -76,7 +76,7 @@
|
||||
break;
|
||||
|
||||
case 'ccache': // Clean cache
|
||||
$cache = new curl_cache;
|
||||
$cache = new curl_cache('repository');
|
||||
$cache->refresh();
|
||||
$action = 'list';
|
||||
break;
|
||||
|
@ -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/');
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user