Search moodle.org's
Developer Documentation

See Release Notes

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

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