Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cache_cleaner task fails because of the use of redis #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
srobotta opened this issue Mar 13, 2025 · 8 comments
Open

cache_cleaner task fails because of the use of redis #246

srobotta opened this issue Mar 13, 2025 · 8 comments

Comments

@srobotta
Copy link

srobotta commented Mar 13, 2025

We have the coderunner version 5.6.2 2025022300 on a Moodle 4.6 installation. The cache cleaner task fails since then:

Execute scheduled task: Purge Old Coderunner Cache Entries - task (qtype_coderunner\task\cache_cleaner)
... started 13:25:29. Current memory use 17.4 MB.
Debugging increased temporarily due to faildelay of 86400
... used 0 dbqueries
... used 0.013164043426514 seconds
Scheduled task failed: Purge Old Coderunner Cache Entries - task (qtype_coderunner\task\cache_cleaner),Strange... the Coderunner grading cache file store cannot be found!?
Backtrace:
* line 94 of /question/type/coderunner/classes/cache_purger.php: call to qtype_coderunner\cache_purger::get_first_file_store()
* line 66 of /question/type/coderunner/classes/task/cache_cleaner.php: call to qtype_coderunner\cache_purger->__construct()
* line 410 of /lib/classes/cron.php: call to qtype_coderunner\task\cache_cleaner->execute()
* line 194 of /admin/cli/scheduled_task.php: call to core\cron::run_inner_scheduled_task()

What I have figured out is, that the task assumes that there is a flle cache in use and deletes files that exceed the given ttl (from the coderunner settings qtype_coderunner | gradecachettl).

First of all, the deletion of cache entries should be handled by the cache itself. I assume this task from coderunner exists because of some bug in the file cache.
The redis cache in Moodle (that we use) implements the same interfaces as the file cache, so these two should be exchangeable. However, the task accesses a private function via a reflection class of the file cache, that exists in this class only.

Could you please check, if that manual cleanup of files is still needed and in case not, remove the manual work there? In my opinion the task doesn't make much sense and seems to be there for historic reasons.

I have disabled the task, also because we do not have the setting qtype_coderunner | enablegradecache enabled at our site, hence we don't use the cache at all.

@kecherou
Copy link

We have the same problem using Redis.

@raveiga
Copy link

raveiga commented May 26, 2025

I have the same problem, with the latest version of Moodle 5.0+ (Build: 20250516)
and the latest version of the plugin qtype_coderunner: 2025052100 and qbehaviour_adaptive_adapted_for_coderunner: 2025012500

Thank you.

@mckeownp
Copy link
Collaborator

Hi everyone,

Thanks for raising the issues you're experiencing with the Coderunner grading cache — and sorry for the trouble it's causing.

To clarify the current situation:

  • The grading cache does not currently support Redis as a cache store. This is primarily because Redis isn't well-suited for the grading cache's intended use case — storing results for extended periods (e.g., weeks), which can lead to memory pressure and potential crashes if default Redis settings are used.

  • There's a bug in the scheduled task that manages the grading cache: it runs regardless of whether the cache is enabled and assumes a file-based cache is in use.

It sounds like many of you have already found the most reliable workaround for now:

  • Disable the grading cache, and
  • Turn off the scheduled task associated with it.

Alternatively, if you'd like to continue using the grading cache, you can switch to a file-based cache store. This allows the scheduled task to function as intended and helps manage old entries. However, Moodle doesn’t make it easy to change the cache store for a specific component without affecting the default application cache. If you manage to configure this successfully, please do share how you did it!

I’m actively working on improving compatibility with Redis, but it’s a tricky fit due to the nature of the grading cache. I’m also updating the cache cleaner logic, though progress has been slowed by changes in Moodle 5.0 — particularly around the question bank system — and the inherent complexity of Moodle’s caching framework.

Please feel free to email/post if you have any further questions/concerns/suggestions.

Cheers,
Paul

@mwuttke
Copy link

mwuttke commented May 26, 2025

We have the same issue using Moodle 4.5, the latest version of the plugin qtype_coderunner: 2025050400 and qbehaviour_adaptive_adapted_for_coderunner: 2025012500 and Redis as cache configured.

@timhunt
Copy link
Collaborator

timhunt commented May 29, 2025

Is there some reason we can't just use the TTL feature when defining this cache?

@mckeownp
Copy link
Collaborator

mckeownp commented Jun 6, 2025

Hi Tim,

The problem with using the TTL setting for caches with a file store back-end is that the file stores don't ever delete old cache entries. File stores enforce the TTL on read by simply ignoring entries that are too old. But, those entries stay on disk forever.

The cache cleaner task is designed to run periodically and delete old cache entries (which are simply files on disk). This is similar to the ttl.php task that Redis has for removing old entries. Unfortunately file stores don't have any clean-up mechanism so I needed to write my own to ensure the cache doesn't use up too much disk space.

But, you are right, it would still be nicer to store the TTL setting in the normal place. I initially used a Coderunner setting instead because I thought the TTL setting in the caches.php file could only be updated by doing a Coderunner version bump. I have now found how to get changes in the caches file to take effect, ie, admin->plugins->cache admin->Rescan definitions - which isn't that easy to find! In my next update, I aim to update the Coderunner cache to use the normal TTL setting as set in the caches.php file and to only run the cleanup on file stores (the Redis cleanup is currently running every hour by default so it can do it's own cleanup).

Redis isn't ideal for the Coderunner cache as Redis runs in memory and entries aren't intended to hang around for long. I would assume the ttl for Redis caches is set to something in the order of minutes or hours, rather than the default two weeks that we use for the Coderunner grading cache. Entries in the grading cache need to be kept for a while to make them useful, eg, you might want to regrade an assignment or exam a few days after it closes to tweak the marking on some of the questions.

Our Coderunner caches can run into tens or hundreds of GB if left alone which would certainly blow the Redis memory limit with long TTL's (if Redis isn't setup carefully, eg, the default for Redis seems to be to just break or stop caching when memory is full, rather than cycling out old entries).

Therefore, once I get the updates in place to deal with Moodle 5 - which is proving to be quite painful. I'll be adding in the recommendation that the grade cache be used with file stores and that anyone who wants to try their luck with a Redis store needs to be aware that longer TTL's will put pressure on memory and therefore the Redis store needs to be setup to deal with memory filling up!

I hope this all makes sense. Feel free come back to me with any further questions or suggestions. The Moodle cache system is way more complex than it first seems, so any guidance will be much appreciated!

Cheers,
Paul

@timhunt
Copy link
Collaborator

timhunt commented Jun 6, 2025

Thanks for explaining. Makes sense.

@micaherne
Copy link

micaherne commented Jun 9, 2025

We're seeing this issue too with redis caching. Thanks for the detailed explanation! I'm not sure it's completely accurate though.

Redis isn't ideal for the Coderunner cache as Redis runs in memory and entries aren't intended to hang around for long.

This is only partially true. Redis can run this way, without any persistence (similarly to memcached), but it can also be configured to persist data indefinitely. The Moodle cachestore_redis plugin advertises that it supports "data guarantee" though, so anyone who has redis configured without persistence basically has a misconfigured cache. Unfortunately I don't think that's explicitly documented in the redis cache store docs.

Would it maybe be worth adding 'requiredataguarantee' => true to the grading cache definition to ensure that it it will only use a cache store that does guarantee the data will persist indefinitely? (I realise this doesn't fix anything where people have redis configured to behave like memcached but I'm not sure that's something that the plugin should need to work around.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants