Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
/lib/db/ -> caches.php (source)

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 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      // Cache for question definitions. This is used by the question_bank class.
  81      // Users probably do not need to know about this cache. They will just call
  82      // question_bank::load_question.
  83      'questiondata' => array(
  84          'mode' => cache_store::MODE_APPLICATION,
  85          'simplekeys' => true, // The id of the question is used.
  86          'requiredataguarantee' => false,
  87          'datasource' => 'question_finder',
  88          'datasourcefile' => 'question/engine/bank.php',
  89      ),
  90  
  91      // HTML Purifier cache
  92      // This caches the html purifier cleaned text. This is done because the text is usually cleaned once for every user
  93      // and context combo. Text caching handles caching for the combination, this cache is responsible for caching the
  94      // cleaned text which is shareable.
  95      'htmlpurifier' => array(
  96          'mode' => cache_store::MODE_APPLICATION,
  97          'canuselocalstore' => true,
  98      ),
  99  
 100      // Used to store data from the config + config_plugins table in the database.
 101      // The key used is the component:
 102      //   - core for all core config settings
 103      //   - plugin component for all plugin settings.
 104      // Persistence is used because normally several settings within a script.
 105      'config' => array(
 106          'mode' => cache_store::MODE_APPLICATION,
 107          'staticacceleration' => true,
 108          'simpledata' => true
 109      ),
 110  
 111      // Groupings belonging to a course.
 112      // A simple cache designed to replace $GROUPLIB_CACHE->groupings.
 113      // Items are organised by course id and are essentially course records.
 114      'groupdata' => array(
 115          'mode' => cache_store::MODE_APPLICATION,
 116          'simplekeys' => true, // The course id the groupings exist for.
 117          'simpledata' => true, // Array of stdClass objects containing only strings.
 118          'staticacceleration' => true, // Likely there will be a couple of calls to this.
 119          'staticaccelerationsize' => 2, // The original cache used 1, we've increased that to two.
 120      ),
 121  
 122      // Used to cache calendar subscriptions.
 123      'calendar_subscriptions' => array(
 124          'mode' => cache_store::MODE_APPLICATION,
 125          'simplekeys' => true,
 126          'simpledata' => true,
 127          'staticacceleration' => true,
 128      ),
 129  
 130      // Cache the course categories where the user has any enrolment and all categories that this user can manage.
 131      'calendar_categories' => array(
 132          'mode' => cache_store::MODE_SESSION,
 133          'simplekeys' => true,
 134          'simpledata' => true,
 135          'invalidationevents' => array(
 136              'changesincoursecat',
 137              'changesincategoryenrolment',
 138          ),
 139          'ttl' => 900,
 140      ),
 141  
 142      // Cache the capabilities list DB table. See get_all_capabilities and get_deprecated_capability_info in accesslib.
 143      'capabilities' => array(
 144          'mode' => cache_store::MODE_APPLICATION,
 145          'simplekeys' => true,
 146          'simpledata' => true,
 147          'staticacceleration' => true,
 148          'staticaccelerationsize' => 2, // Should be main capabilities and deprecated capabilities.
 149          'ttl' => 3600, // Just in case.
 150      ),
 151  
 152      // YUI Module cache.
 153      // This stores the YUI module metadata for Shifted YUI modules in Moodle.
 154      'yuimodules' => array(
 155          'mode' => cache_store::MODE_APPLICATION,
 156      ),
 157  
 158      // Cache for the list of event observers.
 159      'observers' => array(
 160          'mode' => cache_store::MODE_APPLICATION,
 161          'simplekeys' => true,
 162          'simpledata' => true,
 163          'staticacceleration' => true,
 164          'staticaccelerationsize' => 2,
 165      ),
 166  
 167      // Cache used by the {@link core_plugin_manager} class.
 168      // NOTE: this must be a shared cache.
 169      'plugin_manager' => array(
 170          'mode' => cache_store::MODE_APPLICATION,
 171          'simplekeys' => true,
 172          'simpledata' => true,
 173      ),
 174  
 175      // Used to store the full tree of course categories.
 176      'coursecattree' => array(
 177          'mode' => cache_store::MODE_APPLICATION,
 178          'staticacceleration' => true,
 179          'invalidationevents' => array(
 180              'changesincoursecat',
 181          )
 182      ),
 183      // Used to store data for course categories visible to current user. Helps to browse list of categories.
 184      'coursecat' => array(
 185          'mode' => cache_store::MODE_SESSION,
 186          'invalidationevents' => array(
 187              'changesincoursecat',
 188              'changesincourse',
 189          ),
 190          'ttl' => 600,
 191      ),
 192      // Used to store data for course categories visible to current user. Helps to browse list of categories.
 193      'coursecatrecords' => array(
 194          'mode' => cache_store::MODE_REQUEST,
 195          'simplekeys' => true,
 196          'invalidationevents' => array(
 197              'changesincoursecat',
 198          ),
 199      ),
 200      // Used to store state of sections in course (collapsed or not).
 201      'coursesectionspreferences' => [
 202          'mode' => cache_store::MODE_REQUEST,
 203          'simplekeys' => true,
 204          'simpledata' => false,
 205          'staticacceleration' => true,
 206      ],
 207      // Cache course contacts for the courses.
 208      'coursecontacts' => array(
 209          'mode' => cache_store::MODE_APPLICATION,
 210          'staticacceleration' => true,
 211          'simplekeys' => true,
 212          'ttl' => 3600,
 213      ),
 214      // Course reactive state cache.
 215      'courseeditorstate' => [
 216          'mode' => cache_store::MODE_SESSION,
 217          'simplekeys' => true,
 218          'simpledata' => true,
 219      ],
 220      // Used to store data for repositories to avoid repetitive DB queries within one request.
 221      'repositories' => array(
 222          'mode' => cache_store::MODE_REQUEST,
 223      ),
 224      // Used to store external badges.
 225      'externalbadges' => array(
 226          'mode' => cache_store::MODE_APPLICATION,
 227          'simplekeys' => true,
 228          'ttl' => 3600,
 229      ),
 230      // Accumulated information about course modules and sections used to print course view page (user-independent).
 231      // Used in functions:
 232      // - course_modinfo::build_course_section_cache()
 233      // - course_modinfo::inner_build_course_cache()
 234      // - get_array_of_activities()
 235      // Reset/update in functions:
 236      // - rebuild_course_cache()
 237      // - course_modinfo::purge_module_cache()
 238      // - course_modinfo::purge_section_cache()
 239      // - remove_course_contents().
 240      'coursemodinfo' => array(
 241          'mode' => cache_store::MODE_APPLICATION,
 242          'simplekeys' => true,
 243          'canuselocalstore' => true,
 244          'requirelockingbeforewrite' => true
 245      ),
 246      // This is the session user selections cache.
 247      // It's a special cache that is used to record user selections that should persist for the lifetime of the session.
 248      // Things such as which categories the user has expanded can be stored here.
 249      // It uses simple keys and simple data, please ensure all uses conform to those two constraints.
 250      'userselections' => array(
 251          'mode' => cache_store::MODE_SESSION,
 252          'simplekeys' => true,
 253          'simpledata' => true
 254      ),
 255  
 256      // Used to cache activity completion status.
 257      'completion' => array(
 258          'mode' => cache_store::MODE_APPLICATION,
 259          'simplekeys' => true,
 260          'simpledata' => true,
 261          'ttl' => 3600,
 262          'staticacceleration' => true,
 263          'staticaccelerationsize' => 2, // Should be current course and site course.
 264      ),
 265  
 266      // Used to cache course completion status.
 267      'coursecompletion' => array(
 268          'mode' => cache_store::MODE_APPLICATION,
 269          'simplekeys' => true,
 270          'simpledata' => true,
 271          'ttl' => 3600,
 272          'staticacceleration' => true,
 273          'staticaccelerationsize' => 30, // Will be users list of current courses in nav.
 274      ),
 275  
 276      // A simple cache that stores whether a user can expand a course in the navigation.
 277      // The key is the course ID and the value will either be 1 or 0 (cast to bool).
 278      // The cache isn't always up to date, it should only ever be used to save a costly call to
 279      // can_access_course on the first page request a user makes.
 280      'navigation_expandcourse' => array(
 281          'mode' => cache_store::MODE_SESSION,
 282          'simplekeys' => true,
 283          'simpledata' => true
 284      ),
 285  
 286      // Caches suspended userids by course.
 287      // The key is the courseid, the value is an array of user ids.
 288      'suspended_userids' => array(
 289          'mode' => cache_store::MODE_REQUEST,
 290          'simplekeys' => true,
 291          'simpledata' => true,
 292      ),
 293  
 294      // Cache system-wide role definitions.
 295      'roledefs' => array(
 296          'mode' => cache_store::MODE_APPLICATION,
 297          'simplekeys' => true,
 298          'simpledata' => true,
 299          'staticacceleration' => true,
 300          'staticaccelerationsize' => 30,
 301      ),
 302  
 303      // Caches plugins existing functions by function name and file.
 304      // Set static acceleration size to 5 to load a few functions.
 305      'plugin_functions' => array(
 306          'mode' => cache_store::MODE_APPLICATION,
 307          'simplekeys' => true,
 308          'simpledata' => true,
 309          'staticacceleration' => true,
 310          'staticaccelerationsize' => 5
 311      ),
 312  
 313      // Caches data about tag collections and areas.
 314      'tags' => array(
 315          'mode' => cache_store::MODE_REQUEST,
 316          'simplekeys' => true,
 317          'staticacceleration' => true,
 318      ),
 319  
 320      // Grade categories. Stored at session level as invalidation is very aggressive.
 321      'grade_categories' => array(
 322          'mode' => cache_store::MODE_SESSION,
 323          'simplekeys' => true,
 324          'invalidationevents' => array(
 325              'changesingradecategories',
 326          )
 327      ),
 328  
 329      // Store temporary tables information.
 330      'temp_tables' => array(
 331          'mode' => cache_store::MODE_REQUEST,
 332          'simplekeys' => true,
 333          'simpledata' => true
 334      ),
 335  
 336      // Caches tag index builder results.
 337      'tagindexbuilder' => array(
 338          'mode' => cache_store::MODE_SESSION,
 339          'simplekeys' => true,
 340          'simplevalues' => true,
 341          'staticacceleration' => true,
 342          'staticaccelerationsize' => 10,
 343          'ttl' => 900, // 15 minutes.
 344          'invalidationevents' => array(
 345              'resettagindexbuilder',
 346          ),
 347      ),
 348  
 349      // Caches contexts with insights.
 350      'contextwithinsights' => array(
 351          'mode' => cache_store::MODE_APPLICATION,
 352          'simplekeys' => true,
 353          'simpledata' => true,
 354          'staticacceleration' => true,
 355          'staticaccelerationsize' => 1
 356      ),
 357  
 358      // Caches message processors.
 359      'message_processors_enabled' => array(
 360          'mode' => cache_store::MODE_APPLICATION,
 361          'simplekeys' => true,
 362          'simpledata' => true,
 363          'staticacceleration' => true,
 364          'staticaccelerationsize' => 3
 365      ),
 366  
 367      // Caches the time of the last message in a conversation.
 368      'message_time_last_message_between_users' => array(
 369          'mode' => cache_store::MODE_APPLICATION,
 370          'simplekeys' => true, // The conversation id is used.
 371          'simplevalues' => true,
 372          'datasource' => '\core_message\time_last_message_between_users',
 373      ),
 374  
 375      // Caches font awesome icons.
 376      'fontawesomeiconmapping' => array(
 377          'mode' => cache_store::MODE_APPLICATION,
 378          'simplekeys' => true,
 379          'simpledata' => true,
 380          'staticacceleration' => true,
 381          'staticaccelerationsize' => 1
 382      ),
 383  
 384      // Caches processed CSS.
 385      'postprocessedcss' => array(
 386          'mode' => cache_store::MODE_APPLICATION,
 387          'simplekeys' => true,
 388          'simpledata' => true,
 389          'staticacceleration' => false,
 390      ),
 391  
 392      // Caches grouping and group ids of a user.
 393      'user_group_groupings' => array(
 394          'mode' => cache_store::MODE_APPLICATION,
 395          'simplekeys' => true,
 396          'simpledata' => true,
 397          'staticacceleration' => true,
 398      ),
 399  
 400      // This is the user's pre sign-up session cache.
 401      // This cache is used to record the user's pre sign-up data such as
 402      // age of digital consent (minor) status, accepted policies, etc.
 403      'presignup' => array(
 404          'mode' => cache_store::MODE_SESSION,
 405          'simplekeys' => true,
 406          'simpledata' => true,
 407          'ttl' => 1800
 408      ),
 409  
 410      // Caches the first time we analysed models' analysables.
 411      'modelfirstanalyses' => array(
 412          'mode' => cache_store::MODE_REQUEST,
 413          'simplekeys' => true,
 414          'simpledata' => true,
 415      ),
 416  
 417      // Cache the list of portfolio instances for the logged in user
 418      // in the portfolio_add_button constructor to avoid loading the
 419      // same data multiple times.
 420      'portfolio_add_button_portfolio_instances' => [
 421          'mode' => cache_store::MODE_REQUEST,
 422          'simplekeys' => true,
 423          'staticacceleration' => true
 424      ],
 425  
 426      // Cache the user dates for courses set to relative dates mode.
 427      'course_user_dates' => [
 428          'mode' => cache_store::MODE_REQUEST,
 429          'simplekeys' => true,
 430          'simpledata' => true,
 431          'staticacceleration' => true
 432      ],
 433  
 434      // Information generated during the calculation of indicators.
 435      'calculablesinfo' => [
 436          'mode' => cache_store::MODE_REQUEST,
 437          'simplekeys' => false,
 438          'simpledata' => false,
 439      ],
 440  
 441      // The list of content items (activities, resources and their subtypes) that can be added to a course for a user.
 442      'user_course_content_items' => [
 443          'mode' => cache_store::MODE_REQUEST,
 444          'simplekeys' => true,
 445      ],
 446  
 447      // The list of favourited content items (activities, resources and their subtypes) for a user.
 448      'user_favourite_course_content_items' => [
 449          'mode' => cache_store::MODE_APPLICATION,
 450          'simplekeys' => true,
 451      ],
 452  
 453      \core_course\local\service\content_item_service::RECOMMENDATION_CACHE => [
 454          'mode' => cache_store::MODE_APPLICATION,
 455          'simplekeys' => true,
 456      ],
 457  
 458      // Caches contentbank extensions management.
 459      'contentbank_enabled_extensions' => [
 460          'mode' => cache_store::MODE_APPLICATION,
 461          'simplekeys' => true,
 462          'simpledata' => true,
 463          'staticacceleration' => true,
 464      ],
 465      'contentbank_context_extensions' => [
 466          'mode' => cache_store::MODE_REQUEST,
 467          'simplekeys' => true,
 468          'simpledata' => true,
 469          'staticacceleration' => true,
 470      ],
 471  
 472      // Language strings for H5P content-type libraries.
 473      // Key "{$libraryname}/{$language}"" contains translations for a given library and language.
 474      // Key "$libraryname" has a list of all of the available languages for the library.
 475      'h5p_content_type_translations' => [
 476          'mode' => cache_store::MODE_APPLICATION,
 477          'simpledata' => true,
 478      ],
 479  
 480      // File cache for H5P Library files.
 481      'h5p_library_files' => [
 482          'mode' => cache_store::MODE_APPLICATION,
 483          'simplekeys' => true,
 484          'canuselocalstore' => true
 485      ],
 486  
 487      // Cache the grade letters for faster retrival.
 488      'grade_letters' => [
 489          'mode'                   => cache_store::MODE_REQUEST,
 490          'simplekeys'             => true,
 491          'staticacceleration'     => true,
 492          'staticaccelerationsize' => 100
 493      ],
 494  
 495      // Cache for licenses.
 496      'license' => [
 497          'mode' => cache_store::MODE_APPLICATION,
 498          'simplekeys' => true,
 499          'simpledata' => false,
 500      ],
 501  
 502      // Cache the grade setting for faster retrieval.
 503      'gradesetting' => [
 504          'mode'                   => cache_store::MODE_REQUEST,
 505          'simplekeys'             => true,
 506          'staticacceleration'     => true,
 507          'staticaccelerationsize' => 100
 508      ],
 509  
 510      // Course image cache.
 511      'course_image' => [
 512          'mode' => cache_store::MODE_APPLICATION,
 513          'simplekeys' => true,
 514          'simpledata' => true,
 515          'staticacceleration' => true,
 516          'datasource' => '\core_course\cache\course_image',
 517      ],
 518  
 519      // Cache the course categories where the user has access the content bank.
 520      'contentbank_allowed_categories' => [
 521          'mode' => cache_store::MODE_SESSION,
 522          'simplekeys' => true,
 523          'simpledata' => true,
 524          'invalidationevents' => [
 525              'changesincoursecat',
 526              'changesincategoryenrolment',
 527          ],
 528      ],
 529  
 530      // Cache the courses where the user has access the content bank.
 531      'contentbank_allowed_courses' => [
 532          'mode' => cache_store::MODE_SESSION,
 533          'simplekeys' => true,
 534          'simpledata' => true,
 535          'invalidationevents' => [
 536              'changesincoursecat',
 537              'changesincategoryenrolment',
 538              'changesincourse',
 539          ],
 540      ],
 541  
 542      // Users allowed reports according to audience.
 543      'reportbuilder_allowed_reports' => [
 544          'mode' => cache_store::MODE_APPLICATION,
 545          'simplekeys' => true,
 546          'simpledata' => true,
 547          'staticacceleration' => true,
 548          'ttl' => 1800,
 549      ],
 550  
 551      // Cache image dimensions.
 552      'file_imageinfo' => [
 553          'mode' => cache_store::MODE_APPLICATION,
 554          'simplekeys' => true,
 555          'simpledata' => true,
 556          'staticacceleration' => true,
 557          'canuselocalstore' => true,
 558          'staticaccelerationsize' => 100,
 559      ],
 560  );