Moodle cache size and purge_caches.php cli script

Moodle cache size and purge_caches.php cli script

by Евгений Мамаев -
Number of replies: 9
Picture of Plugin developers

Hello!

After about a year of my site being online (currently Moodle 3.9) I have tried to install a few plugins (blocks and course mod) and got stuck in installation process. The request just timeouts and if you try again you get the  same result.

After looking into source code of installation script I have found that Moodle purges all caches prior to installing a new plugin. This purging takes a long time in my case. So I have tried to purge cache via a cli script and it took about 3.5 - 4 hours. After that I have successfully installed my plugin.

Cache storage is configured by default (no additional cache storage engines or stuff like that), Apache 2.4, PHP 7.4, Windows Server environment

So my question is how can I determine Moodle cache size and can it grow to take up all available disk space? How often to purge caches in production environment (purge_caches.php --other and purge_caches.php --muc)?

Average of ratings: -
In reply to Евгений Мамаев

Re: Moodle cache size and purge_caches.php cli script

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
That seems very odd. Cache purging could be slow in earlier versions but that was mostly fixed.

If you are caching to file storage - where is the file storage? Is it very slow NFS or similar?
Average of ratings: Useful (1)
In reply to Howard Miller

Re: Moodle cache size and purge_caches.php cli script

by Евгений Мамаев -
Picture of Plugin developers
File storage is on local NTFS drive
In reply to Евгений Мамаев

Re: Moodle cache size and purge_caches.php cli script

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Ok - I don't speak Microsoft but I don't believe that's anything unusual.

This makes me think something has gone wrong, but I'm really struggling to think what it might be.
In reply to Howard Miller

Re: Moodle cache size and purge_caches.php cli script

by Евгений Мамаев -
Picture of Plugin developers
What was slowing down cache purging in earlier versions?
In reply to Евгений Мамаев

Re: Moodle cache size and purge_caches.php cli script

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I never bothered to find out. On my site (which is huge) it took about 30 mins and then (3.7 I think) it reduced to a couple of minutes.

Do note that we use Redis for the cache. Which I can strongly recommend.
In reply to Евгений Мамаев

Re: Moodle cache size and purge_caches.php cli script

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Just to give us the full picture, what's the exact Moodle version? For example, Moodle 3.9.4+ (Build: 20210204).

What database type and version does the site use?

And is this the thread-safe build of PHP?:

C:\>php -i | findstr /c:"Thread Safety"
Thread Safety => enabled

To answer the other questions, the cache should not grow in an unrestricted way and it should not need to be cleared manually if Moodle is functioning correctly. As far as I know, in a typical single-node installation, the cache size is the size of the cache and localcache folders in Moodledata.

Average of ratings: Useful (1)
In reply to Leon Stringer

Re: Moodle cache size and purge_caches.php cli script

by Евгений Мамаев -
Picture of Plugin developers
Moodle 3.9.1+ (Build: 20200822)
Database MySQL 5.7.20
PHP 7.4.9 x64 Thread safe

I think it woudn`t be a problem if I clear cache once a week. I do not notice any significant slow down after cache is cleared.
Cleared cache today (--other --muc) and after about 8 hours of work cache size approximately 16M (localcache and cache folders)
In reply to Евгений Мамаев

Re: Moodle cache size and purge_caches.php cli script

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

The cache contains minified single-file versions of JavaScript, style sheets and other resources. When the cache is cleared the first browser requests will be noticeably slower to load while these get generated again. Moodle's cron performs housekeeping on the cache (\core\task\cache_cleanup_task and \core\task\cache_cron_task) – is this running on your site? You could monitor the size of the cache folders and see if they grow over time.

The time taken for admin/cli/purge_caches.php is proportional to the size of the cache but it certainly shouldn't take hours. You may need to trace into the code to identify what is causing the delay as, since there are fewer sites on Microsoft Windows, you might be the first to report this problem.

I can't see any changes related to this but I'd recommend installing the latest update, 3.9.4, as there are 6 months of fixes available for your site.