Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
/lib/db/ -> caches.php (source)

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Core cache definitions.
  19   *
  20   * This file is part of Moodle's cache API, affectionately called MUC.
  21   * It contains the components that are requried in order to use caching.
  22   *
  23   * @package    core
  24   * @category   cache
  25   * @copyright  2012 Sam Hemelryk
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  
  29  $definitions = array(
  30  
  31      // Used to store processed lang files.
  32      // The keys used are the revision, lang and component of the string file.
  33      // The static acceleration size has been based upon student access of the site.
  34      'string' => array(
  35          'mode' => cache_store::MODE_APPLICATION,
  36          'simplekeys' => true,
  37          'simpledata' => true,
  38          'staticacceleration' => true,
  39          'staticaccelerationsize' => 30,
  40          'canuselocalstore' => true,
  41      ),
  42  
  43      // Used to store cache of all available translations.
  44      'langmenu' => array(
  45          'mode' => cache_store::MODE_APPLICATION,
  46          'simplekeys' => true,
  47          'simpledata' => true,
  48          'staticacceleration' => true,
  49          'canuselocalstore' => true,
  50      ),
  51  
  52      // Used to store database meta information.
  53      // The database meta information includes information about tables and there columns.
  54      // Its keys are the table names.
  55      // When creating an instance of this definition you must provide the database family that is being used.
  56      'databasemeta' => array(
  57          'mode' => cache_store::MODE_APPLICATION,
  58          'requireidentifiers' => array(
  59              'dbfamily'
  60          ),
  61          'simpledata' => true, // This is a read only class, so leaving references in place is safe.
  62          'staticacceleration' => true,
  63          'staticaccelerationsize' => 15
  64      ),
  65  
  66      // Event invalidation cache.
  67      // This cache is used to manage event invalidation, its keys are the event names.
  68      // Whenever something is invalidated it is both purged immediately and an event record created with the timestamp.
  69      // When a new cache is initialised all timestamps are looked at and if past data is once more invalidated.
  70      // Data guarantee is required in order to ensure invalidation always occurs.
  71      // Persistence has been turned on as normally events are used for frequently used caches and this event invalidation
  72      // cache will likely be used either lots or never.
  73      'eventinvalidation' => array(
  74          'mode' => cache_store::MODE_APPLICATION,
  75          'staticacceleration' => true,
  76          'requiredataguarantee' => true,
  77          'simpledata' => true,
  78      ),
  79  
  80      // Hook callbacks cache.
  81      // There is a static cache in hook manager, data is fetched once per page on first hook execution.
  82      // This cache needs to be invalidated during upgrades when code changes and when callbacks
  83      // overrides are updated.
  84      'hookcallbacks' => array(
  85          'mode' => cache_store::MODE_APPLICATION,
  86          'simplekeys' => true,
  87          'simpledata' => true,
  88          'staticacceleration' => false,
  89          // WARNING: Manual cache purge may be required when overriding hook callbacks.
  90          'canuselocalstore' => true,
  91      ),
  92  
  93      // Cache for question definitions. This is used by the question_bank class.
  94      // Users probably do not need to know about this cache. They will just call
  95      // question_bank::load_question.
  96      'questiondata' => array(
  97          'mode' => cache_store::MODE_APPLICATION,
  98          'simplekeys' => true, // The id of the question is used.
  99          'requiredataguarantee' => false,
 100          'datasource' => 'question_finder',
 101          'datasourcefile' => 'question/engine/bank.php',
 102      ),
 103  
 104      // HTML Purifier cache
 105      // This caches the html purifier cleaned text. This is done because the text is usually cleaned once for every user
 106      // and context combo. Text caching handles caching for the combination, this cache is responsible for caching the
 107      // cleaned text which is shareable.
 108      'htmlpurifier' => array(
 109          'mode' => cache_store::MODE_APPLICATION,
 110          'canuselocalstore' => true,
 111      ),
 112  
 113      // Used to store data from the config + config_plugins table in the database.
 114      // The key used is the component:
 115      //   - core for all core config settings
 116      //   - plugin component for all plugin settings.
 117      // Persistence is used because normally several settings within a script.
 118      'config' => array(
 119          'mode' => cache_store::MODE_APPLICATION,
 120          'staticacceleration' => true,
 121          'simpledata' => true
 122      ),
 123  
 124      // Groupings belonging to a course.
 125      // A simple cache designed to replace $GROUPLIB_CACHE->groupings.
 126      // Items are organised by course id and are essentially course records.
 127      'groupdata' => array(
 128          'mode' => cache_store::MODE_APPLICATION,
 129          'simplekeys' => true, // The course id the groupings exist for.
 130          'simpledata' => true, // Array of stdClass objects containing only strings.
 131          'staticacceleration' => true, // Likely there will be a couple of calls to this.
 132          'staticaccelerationsize' => 2, // The original cache used 1, we've increased that to two.
 133      ),
 134  
 135      // Whether a course currently has hidden groups.
 136      'coursehiddengroups' => array(
 137          'mode' => cache_store::MODE_APPLICATION,
 138          'simplekeys' => true, // The course id the groupings exist for.
 139          'simpledata' => true, // Booleans.
 140          'staticacceleration' => true, // Likely there will be a couple of calls to this.
 141      ),
 142  
 143      // Used to cache calendar subscriptions.
 144      'calendar_subscriptions' => array(
 145          'mode' => cache_store::MODE_APPLICATION,
 146          'simplekeys' => true,
 147          'simpledata' => true,
 148          'staticacceleration' => true,
 149      ),
 150  
 151      // Cache the course categories where the user has any enrolment and all categories that this user can manage.
 152      'calendar_categories' => array(
 153          'mode' => cache_store::MODE_SESSION,
 154          'simplekeys' => true,
 155          'simpledata' => true,
 156          'invalidationevents' => array(
 157              'changesincoursecat',
 158              'changesincategoryenrolment',
 159          ),
 160          'ttl' => 900,
 161      ),
 162  
 163      // Cache the capabilities list DB table. See get_all_capabilities and get_deprecated_capability_info in accesslib.
 164      'capabilities' => array(
 165          'mode' => cache_store::MODE_APPLICATION,
 166          'simplekeys' => true,
 167          'simpledata' => true,
 168          'staticacceleration' => true,
 169          'staticaccelerationsize' => 2, // Should be main capabilities and deprecated capabilities.
 170          'ttl' => 3600, // Just in case.
 171      ),
 172  
 173      // YUI Module cache.
 174      // This stores the YUI module metadata for Shifted YUI modules in Moodle.
 175      'yuimodules' => array(
 176          'mode' => cache_store::MODE_APPLICATION,
 177      ),
 178  
 179      // Cache for the list of event observers.
 180      'observers' => array(
 181          'mode' => cache_store::MODE_APPLICATION,
 182          'simplekeys' => true,
 183          'simpledata' => true,
 184          'staticacceleration' => true,
 185          'staticaccelerationsize' => 2,
 186      ),
 187  
 188      // Cache used by the {@link core_plugin_manager} class.
 189      // NOTE: this must be a shared cache.
 190      'plugin_manager' => array(
 191          'mode' => cache_store::MODE_APPLICATION,
 192          'simplekeys' => true,
 193          'simpledata' => true,
 194      ),
 195  
 196      // Used to store the full tree of course categories.
 197      'coursecattree' => array(
 198          'mode' => cache_store::MODE_APPLICATION,
 199          'staticacceleration' => true,
 200          'invalidationevents' => array(
 201              'changesincoursecat',
 202          )
 203      ),
 204      // Used to store data for course categories visible to current user. Helps to browse list of categories.
 205      'coursecat' => array(
 206          'mode' => cache_store::MODE_SESSION,
 207          'invalidationevents' => array(
 208              'changesincoursecat',
 209              'changesincourse',
 210          ),
 211          'ttl' => 600,
 212      ),
 213      // Used to store data for course categories visible to current user. Helps to browse list of categories.
 214      'coursecatrecords' => array(
 215          'mode' => cache_store::MODE_REQUEST,
 216          'simplekeys' => true,
 217          'invalidationevents' => array(
 218              'changesincoursecat',
 219          ),
 220      ),
 221      // Used to store state of sections in course (collapsed or not).
 222      'coursesectionspreferences' => [
 223          'mode' => cache_store::MODE_REQUEST,
 224          'simplekeys' => true,
 225          'simpledata' => false,
 226          'staticacceleration' => true,
 227      ],
 228      // Cache course contacts for the courses.
 229      'coursecontacts' => array(
 230          'mode' => cache_store::MODE_APPLICATION,
 231          'staticacceleration' => true,
 232          'simplekeys' => true,
 233          'ttl' => 3600,
 234      ),
 235      // Course reactive state cache.
 236      'courseeditorstate' => [
 237          'mode' => cache_store::MODE_SESSION,
 238          'simplekeys' => true,
 239          'simpledata' => true,
 240      ],
 241      // Used to store data for repositories to avoid repetitive DB queries within one request.
 242      'repositories' => array(
 243          'mode' => cache_store::MODE_REQUEST,
 244      ),
 245      // Used to store external badges.
 246      'externalbadges' => array(
 247          'mode' => cache_store::MODE_APPLICATION,
 248          'simplekeys' => true,
 249          'ttl' => 3600,
 250      ),
 251      // Accumulated information about course modules and sections used to print course view page (user-independent).
 252      // Used in functions:
 253      // - course_modinfo::build_course_section_cache()
 254      // - course_modinfo::inner_build_course_cache()
 255      // - get_array_of_activities()
 256      // Reset/update in functions:
 257      // - rebuild_course_cache()
 258      // - course_modinfo::purge_module_cache()
 259      // - course_modinfo::purge_section_cache()
 260      // - remove_course_contents().
 261      'coursemodinfo' => array(
 262          'mode' => cache_store::MODE_APPLICATION,
 263          'simplekeys' => true,
 264          'canuselocalstore' => true,
 265          'requirelockingbeforewrite' => true
 266      ),
 267      // This is the session user selections cache.
 268      // It's a special cache that is used to record user selections that should persist for the lifetime of the session.
 269      // Things such as which categories the user has expanded can be stored here.
 270      // It uses simple keys and simple data, please ensure all uses conform to those two constraints.
 271      'userselections' => array(
 272          'mode' => cache_store::MODE_SESSION,
 273          'simplekeys' => true,
 274          'simpledata' => true
 275      ),
 276  
 277      // Used to cache activity completion status.
 278      'completion' => array(
 279          'mode' => cache_store::MODE_APPLICATION,
 280          'simplekeys' => true,
 281          'simpledata' => true,
 282          'ttl' => 3600,
 283          'staticacceleration' => true,
 284          'staticaccelerationsize' => 2, // Should be current course and site course.
 285      ),
 286  
 287      // Used to cache course completion status.
 288      'coursecompletion' => array(
 289          'mode' => cache_store::MODE_APPLICATION,
 290          'simplekeys' => true,
 291          'simpledata' => true,
 292          'ttl' => 3600,
 293          'staticacceleration' => true,
 294          'staticaccelerationsize' => 30, // Will be users list of current courses in nav.
 295      ),
 296  
 297      // A simple cache that stores whether a user can expand a course in the navigation.
 298      // The key is the course ID and the value will either be 1 or 0 (cast to bool).
 299      // The cache isn't always up to date, it should only ever be used to save a costly call to
 300      // can_access_course on the first page request a user makes.
 301      'navigation_expandcourse' => array(
 302          'mode' => cache_store::MODE_SESSION,
 303          'simplekeys' => true,
 304          'simpledata' => true
 305      ),
 306  
 307      // Caches suspended userids by course.
 308      // The key is the courseid, the value is an array of user ids.
 309      'suspended_userids' => array(
 310          'mode' => cache_store::MODE_REQUEST,
 311          'simplekeys' => true,
 312          'simpledata' => true,
 313      ),
 314  
 315      // Cache system-wide role definitions.
 316      'roledefs' => array(
 317          'mode' => cache_store::MODE_APPLICATION,
 318          'simplekeys' => true,
 319          'simpledata' => true,
 320          'staticacceleration' => true,
 321          'staticaccelerationsize' => 30,
 322      ),
 323  
 324      // Caches plugins existing functions by function name and file.
 325      // Set static acceleration size to 5 to load a few functions.
 326      'plugin_functions' => array(
 327          'mode' => cache_store::MODE_APPLICATION,
 328          'simplekeys' => true,
 329          'simpledata' => true,
 330          'canuselocalstore' => true,
 331          'staticacceleration' => true,
 332          'staticaccelerationsize' => 5
 333      ),
 334  
 335      // Caches data about tag collections and areas.
 336      'tags' => array(
 337          'mode' => cache_store::MODE_REQUEST,
 338          'simplekeys' => true,
 339          'staticacceleration' => true,
 340      ),
 341  
 342      // Grade categories. Stored at session level as invalidation is very aggressive.
 343      'grade_categories' => array(
 344          'mode' => cache_store::MODE_SESSION,
 345          'simplekeys' => true,
 346          'invalidationevents' => array(
 347              'changesingradecategories',
 348          )
 349      ),
 350  
 351      // Store temporary tables information.
 352      'temp_tables' => array(
 353          'mode' => cache_store::MODE_REQUEST,
 354          'simplekeys' => true,
 355          'simpledata' => true
 356      ),
 357  
 358      // Caches tag index builder results.
 359      'tagindexbuilder' => array(
 360          'mode' => cache_store::MODE_SESSION,
 361          'simplekeys' => true,
 362          'simplevalues' => true,
 363          'staticacceleration' => true,
 364          'staticaccelerationsize' => 10,
 365          'ttl' => 900, // 15 minutes.
 366          'invalidationevents' => array(
 367              'resettagindexbuilder',
 368          ),
 369      ),
 370  
 371      // Caches contexts with insights.
 372      'contextwithinsights' => array(
 373          'mode' => cache_store::MODE_APPLICATION,
 374          'simplekeys' => true,
 375          'simpledata' => true,
 376          'staticacceleration' => true,
 377          'staticaccelerationsize' => 1
 378      ),
 379  
 380      // Caches message processors.
 381      'message_processors_enabled' => array(
 382          'mode' => cache_store::MODE_APPLICATION,
 383          'simplekeys' => true,
 384          'simpledata' => true,
 385          'staticacceleration' => true,
 386          'staticaccelerationsize' => 3
 387      ),
 388  
 389      // Caches the time of the last message in a conversation.
 390      'message_time_last_message_between_users' => array(
 391          'mode' => cache_store::MODE_APPLICATION,
 392          'simplekeys' => true, // The conversation id is used.
 393          'simplevalues' => true,
 394          'datasource' => '\core_message\time_last_message_between_users',
 395      ),
 396  
 397      // Caches font awesome icons.
 398      'fontawesomeiconmapping' => array(
 399          'mode' => cache_store::MODE_APPLICATION,
 400          'simplekeys' => true,
 401          'simpledata' => true,
 402          'staticacceleration' => true,
 403          'staticaccelerationsize' => 1
 404      ),
 405  
 406      // Caches processed CSS.
 407      'postprocessedcss' => array(
 408          'mode' => cache_store::MODE_APPLICATION,
 409          'simplekeys' => true,
 410          'simpledata' => true,
 411          'staticacceleration' => false,
 412      ),
 413  
 414      // Caches grouping and group ids of a user.
 415      'user_group_groupings' => array(
 416          'mode' => cache_store::MODE_APPLICATION,
 417          'simplekeys' => true,
 418          'simpledata' => true,
 419          'staticacceleration' => true,
 420      ),
 421  
 422      // This is the user's pre sign-up session cache.
 423      // This cache is used to record the user's pre sign-up data such as
 424      // age of digital consent (minor) status, accepted policies, etc.
 425      'presignup' => array(
 426          'mode' => cache_store::MODE_SESSION,
 427          'simplekeys' => true,
 428          'simpledata' => true,
 429          'ttl' => 1800
 430      ),
 431  
 432      // Caches the first time we analysed models' analysables.
 433      'modelfirstanalyses' => array(
 434          'mode' => cache_store::MODE_REQUEST,
 435          'simplekeys' => true,
 436          'simpledata' => true,
 437      ),
 438  
 439      // Cache the list of portfolio instances for the logged in user
 440      // in the portfolio_add_button constructor to avoid loading the
 441      // same data multiple times.
 442      'portfolio_add_button_portfolio_instances' => [
 443          'mode' => cache_store::MODE_REQUEST,
 444          'simplekeys' => true,
 445          'staticacceleration' => true
 446      ],
 447  
 448      // Cache the user dates for courses set to relative dates mode.
 449      'course_user_dates' => [
 450          'mode' => cache_store::MODE_REQUEST,
 451          'simplekeys' => true,
 452          'simpledata' => true,
 453          'staticacceleration' => true
 454      ],
 455  
 456      // Information generated during the calculation of indicators.
 457      'calculablesinfo' => [
 458          'mode' => cache_store::MODE_REQUEST,
 459          'simplekeys' => false,
 460          'simpledata' => false,
 461      ],
 462  
 463      // The list of content items (activities, resources and their subtypes) that can be added to a course for a user.
 464      'user_course_content_items' => [
 465          'mode' => cache_store::MODE_REQUEST,
 466          'simplekeys' => true,
 467      ],
 468  
 469      // The list of favourited content items (activities, resources and their subtypes) for a user.
 470      'user_favourite_course_content_items' => [
 471          'mode' => cache_store::MODE_APPLICATION,
 472          'simplekeys' => true,
 473      ],
 474  
 475      \core_course\local\service\content_item_service::RECOMMENDATION_CACHE => [
 476          'mode' => cache_store::MODE_APPLICATION,
 477          'simplekeys' => true,
 478      ],
 479  
 480      // Caches contentbank extensions management.
 481      'contentbank_enabled_extensions' => [
 482          'mode' => cache_store::MODE_APPLICATION,
 483          'simplekeys' => true,
 484          'simpledata' => true,
 485          'staticacceleration' => true,
 486      ],
 487      'contentbank_context_extensions' => [
 488          'mode' => cache_store::MODE_REQUEST,
 489          'simplekeys' => true,
 490          'simpledata' => true,
 491          'staticacceleration' => true,
 492      ],
 493  
 494      // Language strings for H5P content-type libraries.
 495      // Key "{$libraryname}/{$language}"" contains translations for a given library and language.
 496      // Key "$libraryname" has a list of all of the available languages for the library.
 497      'h5p_content_type_translations' => [
 498          'mode' => cache_store::MODE_APPLICATION,
 499          'simpledata' => true,
 500      ],
 501  
 502      // File cache for H5P Library ids.
 503      'h5p_libraries' => [
 504          'mode' => cache_store::MODE_APPLICATION,
 505          'simplekeys' => true,
 506          'canuselocalstore' => true
 507      ],
 508  
 509      // File cache for H5P Library files.
 510      'h5p_library_files' => [
 511          'mode' => cache_store::MODE_APPLICATION,
 512          'simplekeys' => true,
 513          'canuselocalstore' => true
 514      ],
 515  
 516      // Cache the grade letters for faster retrival.
 517      'grade_letters' => [
 518          'mode'                   => cache_store::MODE_REQUEST,
 519          'simplekeys'             => true,
 520          'staticacceleration'     => true,
 521          'staticaccelerationsize' => 100
 522      ],
 523  
 524      // Cache for licenses.
 525      'license' => [
 526          'mode' => cache_store::MODE_APPLICATION,
 527          'simplekeys' => true,
 528          'simpledata' => false,
 529      ],
 530  
 531      // Cache the grade setting for faster retrieval.
 532      'gradesetting' => [
 533          'mode'                   => cache_store::MODE_REQUEST,
 534          'simplekeys'             => true,
 535          'staticacceleration'     => true,
 536          'staticaccelerationsize' => 100
 537      ],
 538  
 539      // Course image cache.
 540      'course_image' => [
 541          'mode' => cache_store::MODE_APPLICATION,
 542          'simplekeys' => true,
 543          'simpledata' => true,
 544          'staticacceleration' => true,
 545          'datasource' => '\core_course\cache\course_image',
 546      ],
 547  
 548      // Cache the course categories where the user has access the content bank.
 549      'contentbank_allowed_categories' => [
 550          'mode' => cache_store::MODE_SESSION,
 551          'simplekeys' => true,
 552          'simpledata' => true,
 553          'invalidationevents' => [
 554              'changesincoursecat',
 555              'changesincategoryenrolment',
 556          ],
 557      ],
 558  
 559      // Cache the courses where the user has access the content bank.
 560      'contentbank_allowed_courses' => [
 561          'mode' => cache_store::MODE_SESSION,
 562          'simplekeys' => true,
 563          'simpledata' => true,
 564          'invalidationevents' => [
 565              'changesincoursecat',
 566              'changesincategoryenrolment',
 567              'changesincourse',
 568          ],
 569      ],
 570  
 571      // Users allowed reports according to audience.
 572      'reportbuilder_allowed_reports' => [
 573          'mode' => cache_store::MODE_APPLICATION,
 574          'simplekeys' => true,
 575          'simpledata' => true,
 576          'staticacceleration' => true,
 577          'ttl' => 1800,
 578      ],
 579  
 580      // Cache image dimensions.
 581      'file_imageinfo' => [
 582          'mode' => cache_store::MODE_APPLICATION,
 583          'simplekeys' => true,
 584          'simpledata' => true,
 585          'staticacceleration' => true,
 586          'canuselocalstore' => true,
 587          'staticaccelerationsize' => 100,
 588      ],
 589  
 590      // Cache if a user has the capability to share to MoodleNet.
 591      'moodlenet_usercanshare' => [
 592          'mode' => cache_store::MODE_SESSION,
 593          'simplekeys' => true,
 594          'simpledata' => true,
 595          'ttl' => 1800,
 596          'invalidationevents' => [
 597              'changesincoursecat',
 598              'changesincategoryenrolment',
 599              'changesincourse',
 600          ],
 601      ],
 602  );