Index: course/lib.php
===================================================================
--- course/lib.php	(revision 7793)
+++ course/lib.php	(working copy)
@@ -1183,7 +1183,7 @@
 
     // Ensure cache does not use too much RAM
     if (count($cache) > MAX_MODINFO_CACHE_SIZE) {
-        array_shift($cache);
+        $cache = array_slice($cache, (-1 * MAX_MODINFO_CACHE_SIZE), NULL, true);
     }
 
     return $cache[$course->id];
