-
Improvement
-
Resolution: Fixed
-
Minor
-
4.1.9, 4.2.6, 4.3.3
-
MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
-
MOODLE_404_STABLE
-
MDL-80985-add-purge-course-caches-option-main -
Easy
-
A tiny improvement to allow one, more, or all course caches to be purged via the CLI.
This tracker adds a --courses argument to admin/cli/purge_caches.php and a function in lib/modinfolib.php to allow the purging of all or specific course caches without purging the entire site's cache or all MUC caches.
Similarity to admin/cli/fix_course_sequence.php
It is similar to the admin/cli/fix_course_sequence.php script, but simply invalidates the cache using pre-existing `course_modinfo :: purge_course_cache()` instead of rebuild_course_cache().
Currently, in admin/cli/fix_course_sequence.php, the `rebuild_course_cache()` function only runs if `$errors` are detected in the `course_integrity_check()`. However, in certain cases, there are other course cache related issues not related to the course sequence, which can prevent a course from loading.
That is, `/course/view.php?id=????` can fail to load, e.g. with the error "Invalid course module ID", an error that appears in various forums and trackers with difficult to replicate and hard to diagnose root causes.
A workaround exists (in some cases) to purge an individual course cache via the UI by editing the course (by browsing to `/course/edit.php?id=????`) and editing/saving the course. However, I have seen errors recently involving "Invalid course module ID" due to an incorrect/corrupt course module ID being added, which is required by the navigation, and prevents even the edit screen loading.
Purging all caches or MUC caches for busy site is bad
Purging the whole site's cache - especially on large, busy sites - can be a recipe for disaster, so a more surgical approach is often required just to rebuild the course cache for a course that is effectively blocked/broken and can't be accessed by staff and students.
The `admin/cli/fix_course_sequence.php` script is not able to detect some "Invalid course module ID" errors caused by corrupt course cache which can be caused by sequence issues, so may not be suitable "as-is" to purge course caches in a targeted way. However, it was considered as an option to adjust the script to allow it to forcibly rebuild the course cache solved the issue.
(It's worth noting that if you're using file caches for coursemodinfo, course caches can be found in sitedata to assist with the diagnosis of the cache corruption, such as `<sitedata>/cache/..../core_coursemodinfo/MMM-cache/NNNNNN-HASHHASHHASHHASH.cache` where `MMM` is the first three digits of the course ID, and `NNNNNN` is the full course ID, and HASHHASHHASHHASH is the hash of the cache. Or elsewhere, depending on which cache store and cache type your site is configured to use for coursemodinfo caches.)
See also MDL-37028