Moodle 2 is there a cache for course section 'content'?

Moodle 2 is there a cache for course section 'content'?

by Hans-Christian Sperker -
Number of replies: 7

Hi there,

I have a problem understanding moodle modules. If I add a module to a section of a course the system queries the database to retrieve the name of the module to for printing it in the section (like the name of a label or something). 

If I now change the name of the label in the database, moodle still uses the old name of the label and i can't understand where moodle retrieves this name. Is there something like a cache? I thought moodle would always use the lib.php of a module to get information concerning the module. Is that wrong?

 

Thanks

Hans

Average of ratings: -
In reply to Hans-Christian Sperker

Re: Moodle 2 is there a cache for course section 'content'?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, there is a cache for perfrmance reasons. If you change things through the Moodle UI, it is automatically refreshed.

If you change modules programatically, you need to set course.modinfo to NULL or '', then it will automatically be rebuit the next time the course is viewed.

In reply to Tim Hunt

Re: Moodle 2 is there a cache for course section 'content'?

by Bayu Prakarsa -
@Tim Hunt : Sorry for reviving an old thread.


To change a course section name, I changed the "course_sections" table data (the "name" and the "summary" field values), through the Moodle MySQL database, in a local environment (localhost), but the change is not reflected on the web browser (Google Chrome on Windows 8).

Based on your solution, I looked into the "course" folder, but I didn't find the "modinfo" file. I found a "$modinfo" variable in "course/lib.php" (at line 1873), then I set the value to "NULL", but the cache still exists (I refreshed the web browser, but Moodle still shows the old course section name on the web browser). I use Moodle 3. Did I not set it correctly?

In reply to Bayu Prakarsa

Re: Moodle 2 is there a cache for course section 'content'?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The right way to clear this cache is to call

rebuild_course_cache($courseid, true);

In reply to Tim Hunt

Re: Moodle 2 is there a cache for course section 'content'?

by Bayu Prakarsa -
The URL of my course web page is http://localhost/moodle/course/view.php?id=2, so I guess the course id is 2.


On the "lib.php", I added the following code at the end:


if($_REQUEST['action']=="rebuild_course_cache")

{

   rebuild_course_cache(2, true);

}


Then to run the rebuild_course_cache($courseid, true) function, I inputted the following URL on the web browser:


http://localhost/moodle/course/lib.php?action=rebuild_course_cache


But it doesn't rebuild the course cache (Moodle still shows the old course section name on the web browser). Did I run the rebuild_course_cache($courseid, true) function wrongly?

In reply to Bayu Prakarsa

Re: Moodle 2 is there a cache for course section 'content'?

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you take a look at the first (non-comment) line of course/lib.php, you will find that, like all library files in Moodle, it has the following line:

defined('MOODLE_INTERNAL') || die;
This is there to prevent people from directly accessing library PHP files (just in case they have random side effects). Such files can only be included from other PHP files - they cannot be the main entry point typed into your web browser.

I suggest that if you really want to rebuild the course cache by directly accessing a script, then create a new file somewhere (e.g. /local/clearcache.php ), make sure you require_once the main config.php file, then call the rebuild_course_cache() function from there.