Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-80985

Add --courses argument to purge_caches.php

XMLWordPrintable

    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_404_STABLE
    • MDL-80985-add-purge-course-caches-option-main
    • Easy
    • Hide

      Automated unit test covers manual tests below:

      Create Three Test Courses

      1. Go to Site Administration > Development > Make test course

      1.1. Set:

      "Size of course": XS
      "Course short name": TESTCOURSE-01

      1.2. Select "Create course"

      2. Repeat step (1) to create another two courses (three in total).

      3. On a new site, the three course IDs should be 2, 3 and 4 respectively.

      Generate the Course Caches and Confirm Generated

      1. View all three test courses in a browser to ensure caches are generated.

      2. Confirm four cache files exist for SITE ID 1 and the two COURSE IDs 2, 3 and 4. Assuming  your $CFG->dataroot is set to '/var/lib/sitedata', run the following (for Linux): 

       

      # Site course cache:
      ls -al --full-time /var/lib/sitedata/cache/cachestore_file/default_application/core_coursemodinfo/1-*-cache/*.cache
       
      # Course ID 2 cache:
      ls -al --full-time /var/lib/sitedata/cache/cachestore_file/default_application/core_coursemodinfo/2-*-cache/*.cache
       
      # Course ID 3 cache:
      ls -al --full-time /var/lib/sitedata/cache/cachestore_file/default_application/core_coursemodinfo/3-*-cache/*.cache
       
      # Course ID 4 cache:
      ls -al --full-time /var/lib/sitedata/cache/cachestore_file/default_application/core_coursemodinfo/4-*-cache/*.cache
      

       

      3. Alternatively, view them all at once in two lines (and update DATAROOT to the path you use for $CFG->dataroot), like so:

       

      # Update DATAROOT to the path you use for $CFG->dataroot.
      DATAROOT=/var/lib/sitedata
       
      # List SITE and all course caches
      ls al --full-time ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/1cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/2cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/3cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/4-cache/.cache
      

      4. Note the timestamps of the cache files.

      Purge First Course Cache, View Subject, Confirm Cache Re-built

      1. Purge cache for TESTCOURSE-01 (ID 2), e.g. Run:

      php admin/cli/purge_caches.php --courses=2
      

      2. View the course in a browser to trigger the cache rebuild

      3. Confirm the timestamp has changed, indicating the cache has been regenerated, and confirm that the other caches haven't changed (and don't, if you view them in a browser)

      # Update DATAROOT to the path you use for $CFG->dataroot.
      DATAROOT=/var/lib/sitedata
       
      # List SITE and all course caches
      ls al --full-time ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/1cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/2cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/3cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/4-cache/.cache

      Purge Second Course Cache, View Subject, Confirm Cache Re-built

      Repeat the purge cache step above, but for the TESTCOURSE-02 (ID 3), and check timestamps the same way to ensure only the cache for this course has been regenerated.

      Purge First and Third Course Cache, View Subjects, Confirm Cache Re-built

      Repeat the purge cache step above, but for the TESTCOURSE-01 (ID 2) and TESTCOURSE-03 (ID 4), and check timestamps the same way to ensure only the cache for these courses have been regenerated.

      Purge All Course Caches (including SITE), View Subjects, Confirm Cache Re-built

      1. Repeat the purge cache step above, but without any course ID arguments to purge all caches.

      php admin/cli/purge_caches.php --courses
      

      2. View any course in a browser

      a. Confirm the SITE cache timestamp has changed, indicating the cache has been regenerated
      b. Confirm the cache timestamp for the course viewed has changed, indicating the cache has been regenerated
      c. Confirm no other timestamps have changed (and don't, if viewing those courses)

      3. View another course in a browser

      a. Confirm the cache timestamp for the course viewed has changed, indicating the cache has been regenerated
      b. Confirm no other timestamps have changed (and don't, if viewing those courses)

       

      Show
      Automated unit test covers manual tests below: Create Three Test Courses 1. Go to Site Administration > Development > Make test course 1.1. Set: "Size of course": XS "Course short name": TESTCOURSE-01 1.2. Select "Create course" 2. Repeat step (1) to create another two courses (three in total). 3. On a new site, the three course IDs should be 2, 3 and 4 respectively. Generate the Course Caches and Confirm Generated 1. View all three test courses in a browser to ensure caches are generated. 2. Confirm four cache files exist for SITE ID 1 and the two COURSE IDs 2, 3 and 4. Assuming  your $CFG->dataroot is set to '/var/lib/sitedata', run the following (for Linux):    # Site course cache: ls -al --full-time /var/lib/sitedata/cache/cachestore_file/default_application/core_coursemodinfo/ 1 -*-cache/*.cache   # Course ID 2 cache: ls -al --full-time /var/lib/sitedata/cache/cachestore_file/default_application/core_coursemodinfo/ 2 -*-cache/*.cache   # Course ID 3 cache: ls -al --full-time /var/lib/sitedata/cache/cachestore_file/default_application/core_coursemodinfo/ 3 -*-cache/*.cache   # Course ID 4 cache: ls -al --full-time /var/lib/sitedata/cache/cachestore_file/default_application/core_coursemodinfo/ 4 -*-cache/*.cache   3. Alternatively, view them all at once in two lines (and update DATAROOT to the path you use for $CFG->dataroot), like so:   # Update DATAROOT to the path you use for $CFG->dataroot. DATAROOT=/var/lib/sitedata   # List SITE and all course caches ls al --full-time ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/1cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/2cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/3cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/ 4 -cache/.cache 4. Note the timestamps of the cache files. Purge First Course Cache, View Subject, Confirm Cache Re-built 1. Purge cache for TESTCOURSE-01 (ID 2), e.g. Run: php admin/cli/purge_caches.php --courses= 2 2. View the course in a browser to trigger the cache rebuild 3. Confirm the timestamp has changed, indicating the cache has been regenerated, and confirm that the other caches haven't changed (and don't, if you view them in a browser) # Update DATAROOT to the path you use for $CFG->dataroot. DATAROOT=/var/lib/sitedata   # List SITE and all course caches ls al --full-time ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/1cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/2cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/3cache/.cache ${DATAROOT}/cache/cachestore_file/default_application/core_coursemodinfo/ 4 -cache/.cache Purge Second Course Cache, View Subject, Confirm Cache Re-built Repeat the purge cache step above, but for the TESTCOURSE-02 (ID 3), and check timestamps the same way to ensure only the cache for this course has been regenerated. Purge First and Third Course Cache, View Subjects, Confirm Cache Re-built Repeat the purge cache step above, but for the TESTCOURSE-01 (ID 2) and TESTCOURSE-03 (ID 4), and check timestamps the same way to ensure only the cache for these courses have been regenerated. Purge All Course Caches (including SITE), View Subjects, Confirm Cache Re-built 1. Repeat the purge cache step above, but without any course ID arguments to purge all caches. php admin/cli/purge_caches.php --courses 2. View any course in a browser a. Confirm the SITE cache timestamp has changed, indicating the cache has been regenerated b. Confirm the cache timestamp for the course viewed has changed, indicating the cache has been regenerated c. Confirm no other timestamps have changed (and don't, if viewing those courses) 3. View another course in a browser a. Confirm the cache timestamp for the course viewed has changed, indicating the cache has been regenerated b. Confirm no other timestamps have changed (and don't, if viewing those courses)  

      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

        1. step1.png
          16 kB
          Safat Shahin
        2. (1) 2 Passed -- (Main)MDL-80985.png
          100 kB
          Kim Jared Lucas
        3. (2) 3 Passed -- (Main)MDL-80985.png
          46 kB
          Kim Jared Lucas
        4. (3) 3 Passed -- (Main)MDL-80985.png
          132 kB
          Kim Jared Lucas
        5. (3) 2 Passed -- (Main)MDL-80985.png
          138 kB
          Kim Jared Lucas

            james_w James Williams
            james_w James Williams
            Brendan Heywood Brendan Heywood
            Safat Shahin Safat Shahin
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            1 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 35 minutes
                4h 35m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.