]> git.mjollnir.org Git - moodle.git/commitdiff
Introducing $MCACHE - Memory-based cache
authormartinlanghoff <martinlanghoff>
Wed, 27 Dec 2006 22:44:39 +0000 (22:44 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 27 Dec 2006 22:44:39 +0000 (22:44 +0000)
$MCACHE is initially based on core API that is shared between memcached and
turckmmcache/eaccelerator. The core operations are add(), set() and delete()

This initial implementation uses the PECL-based PHP client. Would be trivial
to add support for a PHP-based client.

The $MCACHE facility can be used for DB cache, text filters cache, and possibly
for sessions.

lib/setup.php
lib/setuplib.php

index dfecd40dc49a797a524d561792e36d5377e128aa..fff6683b00dadd128510a42729f0fd09f72d4702 100644 (file)
@@ -44,6 +44,10 @@ global $CFG;
  * @global object(session) $SESSION
  */
 global $SESSION;
+/** 
+ * Definition of shared memory cache
+ */
+global $MCACHE;
 /**
  * Definition of course type
  * @global object(course) $COURSE
@@ -251,6 +255,12 @@ global $HTTPSPAGEREQUIRED;
     unset($originaldatabasedebug);
     error_reporting($CFG->debug);
 
+/// Shared-Memory cache init -- will set $MCACHE
+/// $MCACHE is a global object that offers at least add(), set() and delete()
+/// with similar semantics to the memcached PHP API http://php.net/memcache
+    if (!empty($CFG->memcached) && !empty($CFG->memcachedhosts)) {
+       init_memcached();
+    }
 
 /// Set a default enrolment configuration (see bug 1598)
     if (!isset($CFG->enrol)) {
index ba4bfb9655e8558d276ad30c179c85111199d855..d8e19a3bb1345416faeda5462a16c5cda5075326 100644 (file)
@@ -209,4 +209,29 @@ function setup_is_unicodedb() {
     return $unicodedb;
 }
 
+function init_memcached() {
+    global $CFG, $MCACHE;
+
+    if (!function_exists('memcache_connect')) {
+        debugging("Memcached is set to true but the memcached extension is not installed");
+        return false;
+    }
+                                               
+    $hosts = split(',', $CFG->memcachedhosts);
+    $MCACHE = new Memcache;
+    if (count($hosts) === 1) {
+        // the faster pconnect is only available
+        // for single-server setups
+        $MCACHE->pconnect($hosts[0]);
+    } else {
+        // multi-host setup will share key space
+        foreach ($hosts as $host) {
+            $host = trim($host);
+            $MCACHE->addServer($host);
+        }
+    }
+
+    return true;
+}
+
 ?>