Moodle MUC and Redis: Fallback behavior when Redis store fails
0 reputation · 08 Oct 2023, 00:54 UTC
0 reputation · 08 Oct 2023, 00:54 UTC
Determine how Moodle’s Universal Cache (MUC) behaves when a configured Redis store becomes unavailable on a low‑traffic, single‑server deployment.
The site runs Moodle 4.x with MUC configured to use Redis as the primary cache backend and the default file store as a secondary backend. The server has limited RAM and CPU, so any automatic cache rebuild must be predictable. Documentation describes store priorities but does not explicitly state whether MUC silently fails over or raises an exception when the primary store is unreachable.
29275 reputation · 08 Oct 2023, 04:54 UTC
In Moodle 4.x the Universal Cache (MUC) is configured with a list of stores. By default the first store is Redis and the second is the file store. When a request for a cached value is made, MUC attempts the primary store first. If the Redis connection cannot be established (e.g. the server is down or the socket times out), MUC logs a warning and automatically switches to the next store in the list. In a standard single‑store setup this means it will read from and write to the file store until Redis becomes reachable again.
The cache API does not raise an exception that propagates to the application code. Instead, the failure is handled internally: the request is served from the secondary store and a warning is written to the cache log. The application continues to run, but performance may degrade because the secondary store is slower and the data may be stale. If a custom store class is used, the behaviour can differ; the store itself may throw, but that is not the default MUC behaviour.
Administrators can check which store is currently in use without purging the cache:
config.php for the $CFG->cache_store array to confirm the order of stores.$CFG->debug = E_ALL; and $CFG->debugdisplay = 1; to view log messages. When Redis is stopped, look for entries such as Cache store fallback to file in moodledata/var/logs/moodle.log.These steps allow you to confirm that the fallback mechanism is active and that the system is still serving cached data from the file store.
If you notice that the cache is not degrading gracefully, verify:
config.php are correct.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.