From 56edc4490dd3d894d3380c3d81c449a1fa9d2653 Mon Sep 17 00:00:00 2001
From: skodak <skodak>
Date: Tue, 29 Jan 2008 17:30:46 +0000
Subject: [PATCH] MDL-13237 rceche limiting through intcachemax finally
 implemented - this should prevent major memory leaks; merged from
 MOODLE_19_STABLE

---
 lib/dmllib.php | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/dmllib.php b/lib/dmllib.php
index a767ca4153..8f885070ba 100644
--- a/lib/dmllib.php
+++ b/lib/dmllib.php
@@ -2572,6 +2572,12 @@ function rcache_set($table, $id, $rec) {
     global $CFG, $MCACHE, $rcache;
 
     if ($CFG->cachetype === 'internal') {
+        if (!isset($rcache->data[$table])) {
+            $rcache->data[$table] = array();
+        }
+        if (!isset($rcache->data[$table][$id]) and count($rcache->data[$table]) > $CFG->intcachemax) {
+            array_shift($rcache->data[$table]);
+        }
         $rcache->data[$table][$id] = clone($rec);
     } else {
         $key   = $table . '|' . $id;
-- 
2.39.5