Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/lib/db/ -> caches.php (source)

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

   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 in accesslib.
 143      'capabilities' => array(
 144          'mode' => cache_store::MODE_APPLICATION,
 145          'simplekeys' => true,
 146          'simpledata' => true,
 147          'staticacceleration' => true,
 148          'staticaccelerationsize' => 1,
 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      // Cache course contacts for the courses.
 201      'coursecontacts' => array(
 202          'mode' => cache_store::MODE_APPLICATION,
 203          'staticacceleration' => true,
 204          'simplekeys' => true,
 205          'ttl' => 3600,
 206      ),
 207      // Used to store data for repositories to avoid repetitive DB queries within one request.
 208      'repositories' => array(
 209          'mode' => cache_store::MODE_REQUEST,
 210      ),
 211      // Used to store external badges.
 212      'externalbadges' => array(
 213          'mode' => cache_store::MODE_APPLICATION,
 214          'simplekeys' => true,
 215          'ttl' => 3600,
 216      ),
 217      // Accumulated information about course modules and sections used to print course view page (user-independed).
 218      // Used in function get_fast_modinfo(), reset in function rebuild_course_cache().
 219      'coursemodinfo' => array(
 220          'mode' => cache_store::MODE_APPLICATION,
 221          'simplekeys' => true,
 222          'canuselocalstore' => true,
 223      ),
 224      // This is the session user selections cache.
 225      // It's a special cache that is used to record user selections that should persist for the lifetime of the session.
 226      // Things such as which categories the user has expanded can be stored here.
 227      // It uses simple keys and simple data, please ensure all uses conform to those two constraints.
 228      'userselections' => array(
 229          'mode' => cache_store::MODE_SESSION,
 230          'simplekeys' => true,
 231          'simpledata' => true
 232      ),
 233  
 234      // Used to cache activity completion status.
 235      'completion' => array(
 236          'mode' => cache_store::MODE_APPLICATION,
 237          'simplekeys' => true,
 238          'simpledata' => true,
 239          'ttl' => 3600,
 240          'staticacceleration' => true,
 241          'staticaccelerationsize' => 2, // Should be current course and site course.
 242      ),
 243  
 244      // Used to cache course completion status.
 245      'coursecompletion' => array(
 246          'mode' => cache_store::MODE_APPLICATION,
 247          'simplekeys' => true,
 248          'simpledata' => true,
 249          'ttl' => 3600,
 250          'staticacceleration' => true,
 251          'staticaccelerationsize' => 30, // Will be users list of current courses in nav.
 252      ),
 253  
 254      // A simple cache that stores whether a user can expand a course in the navigation.
 255      // The key is the course ID and the value will either be 1 or 0 (cast to bool).
 256      // The cache isn't always up to date, it should only ever be used to save a costly call to
 257      // can_access_course on the first page request a user makes.
 258      'navigation_expandcourse' => array(
 259          'mode' => cache_store::MODE_SESSION,
 260          'simplekeys' => true,
 261          'simpledata' => true
 262      ),
 263  
 264      // Caches suspended userids by course.
 265      // The key is the courseid, the value is an array of user ids.
 266      'suspended_userids' => array(
 267          'mode' => cache_store::MODE_REQUEST,
 268          'simplekeys' => true,
 269          'simpledata' => true,
 270      ),
 271  
 272      // Cache system-wide role definitions.
 273      'roledefs' => array(
 274          'mode' => cache_store::MODE_APPLICATION,
 275          'simplekeys' => true,
 276          'simpledata' => true,
 277          'staticacceleration' => true,
 278          'staticaccelerationsize' => 30,
 279      ),
 280  
 281      // Caches plugins existing functions by function name and file.
 282      // Set static acceleration size to 5 to load a few functions.
 283      'plugin_functions' => array(
 284          'mode' => cache_store::MODE_APPLICATION,
 285          'simplekeys' => true,
 286          'simpledata' => true,
 287          'staticacceleration' => true,
 288          'staticaccelerationsize' => 5
 289      ),
 290  
 291      // Caches data about tag collections and areas.
 292      'tags' => array(
 293          'mode' => cache_store::MODE_REQUEST,
 294          'simplekeys' => true,
 295          'staticacceleration' => true,
 296      ),
 297  
 298      // Grade categories. Stored at session level as invalidation is very aggressive.
 299      'grade_categories' => array(
 300          'mode' => cache_store::MODE_SESSION,
 301          'simplekeys' => true,
 302          'invalidationevents' => array(
 303              'changesingradecategories',
 304          )
 305      ),
 306  
 307      // Store temporary tables information.
 308      'temp_tables' => array(
 309          'mode' => cache_store::MODE_REQUEST,
 310          'simplekeys' => true,
 311          'simpledata' => true
 312      ),
 313  
 314      // Caches tag index builder results.
 315      'tagindexbuilder' => array(
 316          'mode' => cache_store::MODE_SESSION,
 317          'simplekeys' => true,
 318          'simplevalues' => true,
 319          'staticacceleration' => true,
 320          'staticaccelerationsize' => 10,
 321          'ttl' => 900, // 15 minutes.
 322          'invalidationevents' => array(
 323              'resettagindexbuilder',
 324          ),
 325      ),
 326  
 327      // Caches contexts with insights.
 328      'contextwithinsights' => array(
 329          'mode' => cache_store::MODE_APPLICATION,
 330          'simplekeys' => true,
 331          'simpledata' => true,
 332          'staticacceleration' => true,
 333          'staticaccelerationsize' => 1
 334      ),
 335  
 336      // Caches message processors.
 337      'message_processors_enabled' => array(
 338          'mode' => cache_store::MODE_APPLICATION,
 339          'simplekeys' => true,
 340          'simpledata' => true,
 341          'staticacceleration' => true,
 342          'staticaccelerationsize' => 3
 343      ),
 344  
 345      // Caches the time of the last message in a conversation.
 346      'message_time_last_message_between_users' => array(
 347          'mode' => cache_store::MODE_APPLICATION,
 348          'simplekeys' => true, // The conversation id is used.
 349          'simplevalues' => true,
 350          'datasource' => '\core_message\time_last_message_between_users',
 351      ),
 352  
 353      // Caches font awesome icons.
 354      'fontawesomeiconmapping' => array(
 355          'mode' => cache_store::MODE_APPLICATION,
 356          'simplekeys' => true,
 357          'simpledata' => true,
 358          'staticacceleration' => true,
 359          'staticaccelerationsize' => 1
 360      ),
 361  
 362      // Caches processed CSS.
 363      'postprocessedcss' => array(
 364          'mode' => cache_store::MODE_APPLICATION,
 365          'simplekeys' => true,
 366          'simpledata' => true,
 367          'staticacceleration' => false,
 368      ),
 369  
 370      // Caches grouping and group ids of a user.
 371      'user_group_groupings' => array(
 372          'mode' => cache_store::MODE_APPLICATION,
 373          'simplekeys' => true,
 374          'simpledata' => true,
 375          'staticacceleration' => true,
 376      ),
 377  
 378      // This is the user's pre sign-up session cache.
 379      // This cache is used to record the user's pre sign-up data such as
 380      // age of digital consent (minor) status, accepted policies, etc.
 381      'presignup' => array(
 382          'mode' => cache_store::MODE_SESSION,
 383          'simplekeys' => true,
 384          'simpledata' => true,
 385          'ttl' => 1800
 386      ),
 387  
 388      // Caches the first time we analysed models' analysables.
 389      'modelfirstanalyses' => array(
 390          'mode' => cache_store::MODE_REQUEST,
 391          'simplekeys' => true,
 392          'simpledata' => true,
 393      ),
 394  
 395      // Cache the list of portfolio instances for the logged in user
 396      // in the portfolio_add_button constructor to avoid loading the
 397      // same data multiple times.
 398      'portfolio_add_button_portfolio_instances' => [
 399          'mode' => cache_store::MODE_REQUEST,
 400          'simplekeys' => true,
 401          'staticacceleration' => true
 402      ],
 403  
 404      // Cache the user dates for courses set to relative dates mode.
 405      'course_user_dates' => [
 406          'mode' => cache_store::MODE_REQUEST,
 407          'simplekeys' => true,
 408          'simpledata' => true,
 409          'staticacceleration' => true
 410      ],
 411  
 412      // Information generated during the calculation of indicators.
 413      'calculablesinfo' => [
 414          'mode' => cache_store::MODE_REQUEST,
 415          'simplekeys' => false,
 416          'simpledata' => false,
 417      ],
 418  
 419      // The list of content items (activities, resources and their subtypes) that can be added to a course for a user.
 420      'user_course_content_items' => [
 421          'mode' => cache_store::MODE_REQUEST,
 422          'simplekeys' => true,
 423      ],
 424  
 425      // The list of favourited content items (activities, resources and their subtypes) for a user.
 426      'user_favourite_course_content_items' => [
 427          'mode' => cache_store::MODE_APPLICATION,
 428          'simplekeys' => true,
 429      ],
 430  
 431      \core_course\local\service\content_item_service::RECOMMENDATION_CACHE => [
 432          'mode' => cache_store::MODE_APPLICATION,
 433          'simplekeys' => true,
 434      ],
 435  
 436      // Caches contentbank extensions management.
 437      'contentbank_enabled_extensions' => [
 438          'mode' => cache_store::MODE_APPLICATION,
 439          'simplekeys' => true,
 440          'simpledata' => true,
 441          'staticacceleration' => true,
 442      ],
 443      'contentbank_context_extensions' => [
 444          'mode' => cache_store::MODE_REQUEST,
 445          'simplekeys' => true,
 446          'simpledata' => true,
 447          'staticacceleration' => true,
 448      ],
 449  
 450      // Language strings for H5P content-type libraries.
 451      // Key "{$libraryname}/{$language}"" contains translations for a given library and language.
 452      // Key "$libraryname" has a list of all of the available languages for the library.
 453      'h5p_content_type_translations' => [
 454          'mode' => cache_store::MODE_APPLICATION,
 455          'simpledata' => true,
 456      ],
 457  
 458      // File cache for H5P Library files.
 459      'h5p_library_files' => [
 460          'mode' => cache_store::MODE_APPLICATION,
 461          'simplekeys' => true,
 462          'canuselocalstore' => true
 463      ],
 464  
 465      // Cache the grade letters for faster retrival.
 466      'grade_letters' => [
 467          'mode'                   => cache_store::MODE_REQUEST,
 468          'simplekeys'             => true,
 469          'staticacceleration'     => true,
 470          'staticaccelerationsize' => 100
 471      ],
 472  
 473      // Cache for licenses.
 474      'license' => [
 475          'mode' => cache_store::MODE_APPLICATION,
 476          'simplekeys' => true,
 477          'simpledata' => false,
 478      ],
 479  
 480      // Cache the grade setting for faster retrieval.
 481      'gradesetting' => [
 482          'mode'                   => cache_store::MODE_REQUEST,
 483          'simplekeys'             => true,
 484          'staticacceleration'     => true,
 485          'staticaccelerationsize' => 100
 486      ],
 487  );