Moodle cache stores: when a cluster needs more than the default mapping
A single Moodle web server can usually run on the default cache mapping, but a cluster with several web nodes or heavy traffic needs deliberate placement of cache stores. The decision comes down to which cache definitions can stay local to each node, which must be shared across all nodes, and which large items belong in files. In Moodle, a cache store is the backend that holds data for a cache definition, and a cache definition is the named set of data (such as session-independent lookups or request-level data) that the application asks to cache. Administrators map each definition to a store under Site administration, in the cache configuration page, and the mapping decides where each read and write lands.
The three store types covered here behave differently. The APCu store keeps data in the memory of each PHP process pool on one node, so reads are fast but nothing is shared between web nodes. The Redis store is shared by every node that points at the same server, which suits data that must be consistent across the cluster. The file store writes to disk and suits large items that are costly to hold in memory, but it depends on how the directory is shared. You should change the default mapping when nodes disagree about cached data, when a single store becomes a bottleneck, or when large definitions crowd out small hot ones.
Before you change anything, confirm which Moodle version and PHP extensions your nodes run, whether APCu is enabled for the web SAPI on every node, and where your Redis server sits relative to the web tier. Then list the cache definitions in use and decide, for each, whether local or shared data is acceptable. Treat that mapping as a design artifact and test it under realistic concurrency before it reaches production, because a mapping that looks correct on one node can behave differently once requests spread across the cluster.
What APCu, Redis and file stores each do well
Moodle lets each cache definition choose its own store, so the decision is rarely one store for everything. The four options below differ in where data lives, whether nodes share it, and what happens when they lose it, and those differences decide which definitions belong where.
APCu for hot local data
APCu keeps values in the memory of each PHP-FPM worker pool on one web node. Reads are fast and need no network hop, which suits small, frequently read items such as language strings and configuration. The trade-off is locality: each node holds its own copy, so an update made on one node is not seen by the others until their copies expire or are purged. Check that APCu is enabled in the PHP build your web nodes run, and size it so hot items are not evicted.
Redis as the shared store
Redis is a network service that every web node and cron runner can reach, so a cache written on one node is visible to all of them. This is the usual choice for cluster-wide definitions where consistency across nodes matters. The trade-off is failure behaviour: if Redis is unavailable or evicts keys under memory pressure, Moodle must rebuild data from the database, so confirm the Redis memory policy and the connection timeouts before you rely on it.
File stores for large items
The file store writes each cache item to disk, which gives room for large values that would crowd memory in APCu or Redis. Its weakness is sharing: on a cluster, a file store on local disk is private to one node, and a file store on shared storage adds latency and locking to every read. Confirm the cache directory location with the shared and local directory settings for your cluster before you choose this store.
Application and session modes
Moodle maps definitions to one of three modes: application caches are shared across users, session caches hold per-user data for the life of a login, and request caches last for a single page request. Session data belongs in a session store, not an application store, because its lifetime and locking differ. Request caches need no shared store at all, so they should stay in the in-process default. Review the mode of each definition before you move it.
Store availability by Moodle version
Which stores a site can select depends on the Moodle version and the plugins installed, so the list below must be checked against the release you run. Moodle 5.1 requires 64-bit PHP 8.2 or later, and Moodle 5.3 requires 64-bit PHP 8.3 or later, which matters because APCu and Redis extensions must match the PHP build. Confirm store availability in the cache administration page of your exact version before you write the mapping.
Moodle 5.1 notesWhich cache mode and store fits each cache definition
This table compares Moodle cache modes and stores against the kind of data each cache definition holds. Read each row as a question about the data: how long it lives, who shares it, and how large it is. The main takeaway is that the default mapping suits a single server, while a clustered site needs definitions moved deliberately onto shared or local stores.
| Cache mode or store | Best fit | Trade-off | When to choose it |
|---|---|---|---|
| Application cache on APCu | Hot, small, read-mostly data used on every web request | Local to each PHP node, so entries are not shared and may differ between nodes | Per-node definitions such as configuration or language strings that tolerate node-local copies |
| Application cache on Redis | Shared data that every web node must see consistently | Network round trip per read, and Redis becomes a dependency to monitor | Definitions where one node's invalidation must reach all nodes in a cluster |
| Application cache on file | Large items that are expensive to hold in memory | Slower reads than memory stores, and shared file paths must be reachable by all nodes | Large or rarely read items, with the cache directory placed on storage that suits the site |
| Session cache on Redis | Session data for a cluster of web nodes | Session locking adds load on Redis, and a poorly sized instance slows every page | Multi-node sites that cannot rely on sticky sessions at the load balancer |
| Session cache on file or database | Single-server sites or small deployments | Does not scale across nodes without shared storage and sticky routing | Single-node installations where simplicity matters more than horizontal growth |
| Request cache on APCu or in-process | Data needed once within a single request | Discarded at the end of each request, so it saves no work between requests | Repeated lookups inside one page load, where cross-request sharing is not wanted |
| Definitions mapped by default | Works for a single server with no extra services | May place shared data on local stores, causing drift between web nodes | Starting point only. Review each definition in the cache configuration admin page before a cluster goes live |
| Definitions mapped for a tuned cluster | Shared data on Redis, node-local data on APCu, large items on file | Needs load testing and monitoring of each store's hit rate and latency | Target state for multi-node production, confirmed against your own traffic profile |
How to map cache definitions to stores in order
This sequence takes a Moodle site from a clean cache configuration to definitions mapped onto Redis, APCu and file stores, with a check at each step so a broken store is found before users reach it.
Confirm Moodle version and PHP extensions
Before changing anything, the Moodle administrator records the installed Moodle version and the PHP version on every web node. The Moodle 5.1 release notes require 64-bit PHP 8.2 or later, and the Moodle 5.3 release notes require 64-bit PHP 8.3 or later, so confirm the release you run against those requirements. Then check that the Redis and APCu PHP extensions are loaded on each node with the
php -mcommand. This step is complete when every node reports the same Moodle version and the extensions you plan to use appear in the output.Prepare Redis and APCu on each node
The platform team installs and enables the APCu extension on each web node and sets its shared memory size in the PHP configuration, then starts a Redis server reachable from every node over a private network. Set the APCu memory allocation and Redis memory limit with your own sizing, and confirm access control on Redis is enabled. Verify from each web node that Redis answers a ping and that APCu reports as enabled in a PHP info page or CLI check. This step is done when each node can reach Redis and APCu is active on all of them.
Add store instances in the cache admin page
In Moodle, open Site administration, then the cache configuration page, and add a store instance for each backend you prepared: a Redis store pointing to your Redis host, an APCu store, and a file store. Enter the Redis server address and any authentication details, and use a distinct prefix so this site's keys do not collide with other applications sharing the server. Save each instance. The check is that each store appears in the list with a status indicating it is ready, and that the Redis store reports successful connection rather than an error message.
Map definitions to stores
Still on the cache configuration page, open the stores-mapping view and assign each cache definition to a store. Place small, frequently read, per-request or per-process data such as language strings and configuration on APCu where the node-local store is appropriate, place data that must be shared across all web nodes such as sessions and application caches on Redis, and place large items such as course-level caches or definitions holding big objects on the file store. Keep the mapping in a written record so later changes are reviewed. The check is that the mapping view lists every definition with a store and no definition is left on a store that is not ready.
Set the cache mode for each definition
Moodle cache definitions use an application, session or request mode, and the mode determines how long data lives and which store the definition can use. Confirm each definition's mode matches its role: session definitions stay tied to user sessions, request definitions last for one page load, and application definitions are shared across requests. Do not assign a session-mode definition to a store that is not shared across all nodes, because a user could lose state on a different web node. The check is that each definition shows the mode you intended and the mapping matches the mode.
Verify the stores report as working
Use the cache store status and the cache test or purge actions in the admin page to confirm each store reads and writes successfully. Then load a few course and dashboard pages and check the Moodle logs or the cache statistics view for hit and miss counts on the mapped definitions. Repeat the check from a second web node to confirm Redis-backed data is visible across nodes. The step is complete when every store reports working, hits appear for the mapped definitions, and a value written on one node can be read on another.
Test the mapping under load before relying on it
Before the mapping carries real users, run a load test that mirrors your expected course and quiz traffic against a staging copy, and watch Redis memory use, APCu fill, file store disk growth and miss rates for each definition. Look for evictions or stale data appearing under pressure, and adjust store sizes or definition placement if they do. Record the results and the configuration that produced them so the mapping can be reproduced after upgrades. The step is done when the test runs without store errors and the results are documented for your operations team.
How a Moodle request reaches its cache stores
A request starts at the load balancer and lands on one of several web nodes running Moodle. Each node keeps APCu as a local store for hot data that never needs to be shared, while Redis holds the shared application and session caches that every node must see. Large items go to a shared file store reached from the node. Check that the Redis trust boundary covers network access and TLS, and that APCu is used only for data that is safe to differ between nodes.
Request flow from the load balancer to the local, shared and file cache stores.
Questions teams ask before changing Moodle cache stores
Can our in-house team map Moodle cache stores to Redis and APCu themselves?
Yes, many teams can, provided they have engineers comfortable with PHP, Moodle administration and their own server stack. The work is mostly configuration: defining cache stores in the Moodle admin interface, assigning cache definitions to stores by mode, and confirming that each node sees the same shared data. The harder part is judgment about which definitions belong in APCu, which belong in Redis and which should stay on files, and that judgment is easier to make with load evidence in hand. Ask whether your team has run Moodle under concurrent traffic before, since mistakes usually appear only under load.
What makes the effort for a cache store change grow or shrink?
The main drivers are the number of web nodes, how many cache definitions you intend to remap, whether those caches must be shared across nodes or can stay local, and which Moodle version you run. A two-node site with default mappings is a much smaller job than a larger cluster where session, application and request caches interact with shared directories and load balancers. Version matters because cache definitions and admin screens change between releases, so the mapping work must be checked against your exact version. Ask the implementer to list each driver and how it changes their estimate.
How long does it take to validate a cache store change?
Validation time depends on how many environments you have, how representative your test data is and how much load testing you want before production. The work usually runs in stages: a mapping in a staging copy, functional checks of courses, quizzes and logins, then a controlled load test that compares page times and cache hit behavior against a baseline. Each stage can reveal a need to adjust mappings, so plan for at least one iteration. Ask for the stage list and the entry and exit criteria for each stage in writing, rather than a single duration with no breakdown.
What access and tools will the work need from our side?
Expect to provide shell or deployment access to every web node and the Redis or APCu hosts involved, a staging environment that matches production closely enough to be useful, a copy or representative sample of course and user data, and a monitoring view of CPU, memory and Redis. For load testing you need a tool that can replay realistic user journeys, such as logins, course views and quiz attempts, and a window in which the test can run without affecting real users. Confirm how Redis credentials and network rules will be handled, and who approves production changes.
Does the change affect data security or access to Redis?
It can. Redis then holds cached data that may include user-related content, so it should be reachable only from Moodle nodes, protected with authentication and TLS where your environment supports it, and placed on a private network segment. APCu is local to each PHP process pool and is not shared, which limits exposure but also limits what it can hold. Ask how the plan treats cache contents, key naming, eviction and access logs, and confirm with your security team which network zones and credentials are allowed.
What should a quote for this work include?
A written quote should state the scope in concrete terms: which Moodle version and nodes are covered, which cache definitions are reviewed, which stores are in use, and whether the work includes configuration only or also load testing and a runbook. It should list deliverables such as a mapping document, a test report comparing before and after results and rollback steps. It should separate one-time work from any recurring checks after upgrades, name the environments used for testing and state what the client must provide. DeployOpen agrees scope, deliverables and timelines in writing before work starts, and does not publish a price list.
Do we need to retest cache mappings after a Moodle upgrade?
Usually yes, because cache definitions, default mappings and admin pages can change between Moodle releases. Check the release notes for the version you are moving to before the upgrade, and repeat functional and load checks on staging after it. Your Moodle version also sets the minimum server stack, so confirm PHP and database requirements at the same time. Ask whether the plan includes a post-upgrade check of cache behavior, since it is easy to omit from an upgrade project.
Security and operational risks of shared cache stores
A shared Redis store, local APCu caches and file caches each carry different exposure and failure modes. The cards below cover the checks that matter most when several Moodle web nodes depend on the same cache layer.
Redis exposure and authentication
Redis is often deployed on a private subnet with no password, which makes any host that can reach its port a potential reader of cached Moodle data. Confirm that Redis listens only on the interfaces your web nodes use, that access is restricted by firewall rules or network policy, and that the server requires authentication. Review the Redis configuration for the bind and requirepass settings on every node, not just the first one.
TLS between nodes
Cache traffic between Moodle web nodes and Redis crosses the network in plain text unless you enable TLS. Moodle's Redis cache store can be configured for TLS, so confirm with your Moodle version and the store documentation which options apply to your setup. Plan certificate issuance and rotation before go-live, because a certificate expiry will break every node at once.
Cache data sensitivity
Cache definitions can hold user-specific data, such as permission and session-adjacent values, so a shared cache is not a neutral store. Review which definitions map to Redis and which stay in APCu or file storage, and confirm that the same cache keys are not readable by unrelated applications on the same Redis instance. Keep a written list of definitions by store so a security review can trace where each item lives.
Eviction and memory limits
When Redis reaches its memory limit, the eviction policy decides which keys are removed. Check the maxmemory and maxmemory-policy values, and test a cache-heavy peak to see whether useful entries are evicted before they expire. A policy that evicts keys under pressure can cause cache misses across all nodes at the same moment, so size memory against the working set you measure rather than the default.
Failover behaviour
A single Redis instance is a shared point of failure, and a failover to a replica can take time and may lose recent writes. Decide in advance how Moodle should behave when the store is unreachable, and confirm that the web nodes degrade to slower responses rather than errors. Rehearse a failover in a staging cluster and record how long sessions and caches take to recover.
Consistent node configuration
Each web node reads its own config.php, so a missing or mistyped cache store definition on one node can send that node to a different store or to the file cache. Keep the store definitions in one version-controlled file that all nodes deploy, and check the cache store admin page on every node after a change. Use the same Moodle release and plugin set on each node, since a mismatch can cause cache definitions to behave differently.
How to test the cache mapping under load before peak
Test the cache mapping with a load profile that matches how your users really hit Moodle, not with a generic web benchmark. Start from the cache definitions your site actually uses: in the Moodle admin cache configuration, note which definitions are mapped to APCu, which to Redis and which to file stores, and which run in application, session or request mode. A useful test script then exercises those paths in proportion: course views and navigation for many users, quiz attempts that write answers and call the question cache, grade and gradebook reads, and logins that create sessions. Use a copy of production-sized data, because cache hit behavior depends heavily on course and user volume. Confirm with your load testing tool and Moodle version which requests your test scenarios will generate before you trust the numbers.
Measure three things per store, not only page response time. Track hit rates for each cache definition, latency of calls to Redis and APCu, and the size and eviction behavior of each store. For Redis, watch memory use and evictions against the memory limit you have set, since a shared store that starts evicting session or application entries under load will look like a slow Moodle with no obvious error. For APCu, watch whether the shared memory segment fills, because a full local store silently pushes traffic back to the database or file layer. Also watch session lock waits, which show up as requests queuing behind one another for the same session rather than as slow queries. Record these figures for each run so that a change can be compared with a known baseline.
Repeat the same test after every change to a cache mapping, store setting, memory allocation or web node count, and again after each Moodle minor update that touches caching code. Treat the test as part of the exam-day plan: the runbook should name the scenarios that were proven, the thresholds the team accepted, and the signals that would trigger a rollback to a known-good mapping. Schedule the final run well before the peak window, leaving time to fix what the run exposes. Your own platform owners should confirm the peak profile, because the test is only as representative as the scenario you agree on.
Limits to confirm in your own environment
Cache store support depends on the exact Moodle release, the PHP build and the cache servers you run. The cards below list the limits to verify before you map definitions to stores, and each one should be confirmed with vendor documentation and your own load tests.
Store support for your release
Cache store plugins and the cache API can change between Moodle versions, so the store you plan around in one release may behave differently in another. Confirm which cache store plugins your exact release ships or supports, and check the release notes for any cache changes. Moodle 5.1 requires 64-bit PHP 8.2 or later, so confirm your starting point against the release you actually plan to run before designing the mapping.
Moodle 5.1 notesPHP extensions and versions
APCu and Redis access from PHP depend on extensions being installed and enabled for the same SAPI that serves Moodle, including PHP-FPM and CLI. A mismatch can leave cron or CLI tasks on a different cache path than web requests. Confirm the extension versions against your PHP build, and check that the extension is loaded for every process that touches Moodle caches.
Redis version and deployment mode
Whether you run a single Redis instance, a primary with replicas, or a clustered deployment changes how cache keys, failover and eviction behave. Confirm the Redis version against the PHP client and Moodle's Redis cache store requirements, and confirm the eviction policy so cache entries are not dropped unexpectedly. Ask the vendor how failover affects connections that Moodle has already opened.
APCu shared or per process
APCu stores data in shared memory local to one PHP host, and each PHP-FPM pool or worker set has its own segment. Cache hits on one web node do not appear on another, so the same definition may behave differently across a cluster. Confirm the APCu memory size, the apc.shm_size setting, and whether your deployment reloads PHP in a way that clears the cache.
Public document root for 5.1
From Moodle 5.1, the web server document root must point to the new /public directory rather than the main Moodle folder. Cache paths and file serving rules in your web server config must match that layout, or requests can reach directories they should not. Check the dirroot path your cache and file aliases use, and confirm the web server rules after any move to 5.1 or later.
Capacity of your hosts
Memory and disk on each web node, the Redis host and any file cache location decide how many entries you can hold before eviction or slowdown. Measure the size of your largest cache items under real course traffic, and test the mapping with a load profile that mirrors peak activity. Ask your hosting team for memory headroom figures, and record what your own tests show rather than relying on defaults.
How DeployOpen scopes the cache store work
DeployOpen starts cache store work with a review of the mapping the site runs today. In Moodle, the cache definitions and their store assignments live in the administration cache configuration screen, and the current mapping is the baseline for everything that follows. The review records which definitions are assigned to which stores in application, session and request modes, which stores are configured and reachable, which definitions use the file store, and whether any definition relies on a default that nobody chose on purpose. It also captures the web nodes, PHP versions and any APCu or Redis instances already in the environment, because those facts decide which mappings are even possible. Ask for this inventory to be part of any quote, since it sets the size of the work.
The review produces a written scope that the client signs before build starts. That scope names the definitions and stores in play, the environments that will receive the change (typically development, staging and production), the load test used as acceptance evidence, and the rollback steps for each change. It also states who owns decisions the partner cannot make alone, such as Redis hosting, memory limits, network rules between web nodes and the cache host, and the change window for production. Clients should confirm that the scope covers the infrastructure they control, including how Redis is reached and secured and which team patches the cache hosts. Scope changes after sign-off should go through the same written route, with effort and schedule impact stated before work continues.
Implementation happens in the client's own environments, using the client's configuration management and change process. DeployOpen applies the mapping change in staging first, runs the agreed load test and compares hit rates, lock behavior and response times against the baseline, then promotes the change to production in the agreed window. Results are kept as evidence for the client's operations team. At the end, DeployOpen documents the final mapping: each definition, its store and mode, the configuration keys that changed, the cache host and failover assumptions, and the steps to revert. That document becomes the reference operations staff use when a later upgrade or new plugin adds cache definitions. Clients should ask for the document format and ownership before signing, so it stays usable after the engagement ends.
How DeployOpen delivers Moodle cache and performance work
DeployOpen plans and implements Moodle cache store mappings inside infrastructure you control, starting from a written scope that names the cache definitions, stores and load targets involved. Each change is built, tested under load and documented so your own team can run and extend it after handover.
How we scope
- The written scope lists which Moodle cache definitions move to APCu, Redis or file stores, and which stay on defaults.
- We agree the web node count, expected concurrency and session mode before any configuration change is made.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
How we build
- We configure the cache stores and mappings in a non-production copy of your Moodle site first, using your server stack.
- Redis, APCu and file store settings are tested for each application, session and request mode before promotion.
- We run load tests against the mapping and record hit rates, latency and any lock or eviction problems we find.
How we hand over
- You receive the final mapping, store settings, server configuration and load test results in a handover document.
- Runbooks cover cache clearing, Redis failover behavior, APCu limits per node and rollback steps.
- Your administrators are walked through the configuration and the checks they should run after each Moodle upgrade.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer for cache changes after go-live.
- Retainer work can re-run load tests when Moodle versions, plugins or traffic patterns change.
- Confirm the support hours, response expectations and upgrade cadence in writing before you sign.

