Moodle cache definition missing invalidation event for a plugin write path
0 reputation · 24 Oct 2022, 02:17 UTC
0 reputation · 24 Oct 2022, 02:17 UTC
Moodle's MUC lets a cache definition in db/cache.php declare a TTL and dependency events, fixing the freshness contract in code rather than exposing it as a teacher- or course-level setting.
For a plugin read path serving data to teachers, a write path that updates the underlying record but misses the declared invalidation event can leave the old value served until TTL expiry or an administrative purge.
Where static acceleration is used, the file-based copy is refreshed on purge rather than expiring per TTL, so the nominal TTL does not bound staleness.
Teachers and students cannot force a global refresh, so policy must not depend on end users purging; external stores may also evict entries independently of TTL. Because cache-definition options and purge paths vary across Moodle releases, confirm behavior on the deployed version.
37775 reputation · 24 Oct 2022, 08:09 UTC
Acceptable staleness: minimal, ideally cleared immediately after the underlying record changes; rely on declared invalidation events and treat TTL only as a backstop.
The cache definition in db/cache.php can specify TTL and invalidation events. If a write path updates the record but does not raise the event the definition listens for, the old value may remain cached until TTL expires or an admin purge runs, which is unsafe for real‑time teaching data.
Moodle’s MUC mechanism fixes the freshness contract in code; audit every write path that mutates the record — standard forms, web services, task actions, import/export, backup/restore, migrations, and any direct SQL — to ensure the declared event is triggered or the cache is explicitly purged.
db/cache.php to verify TTL, invalidationevents, static acceleration, and store settings.Please confirm the Moodle major/minor version and whether static acceleration or a file‑based store is in use, as these details affect cache behavior and the recommended fix.
Use comments to ask for clarification. Post a solution as an answer.
37,775 reputation · 24 Oct 2022, 13:02 UTC
The reliance on declared invalidation events for plugin write paths is critical for data freshness.
For version assumptions (e.g., Moodle 4.x), tracing the specific write path to confirm event emission is the practical verification step.