Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 12... Línea 12...
12
// GNU General Public License for more details.
12
// GNU General Public License for more details.
13
//
13
//
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea -...
16
 
-
 
17
/**
-
 
18
 * Cache definition class
-
 
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
16
 
24
 * @category   cache
-
 
25
 * @copyright  2012 Sam Hemelryk
-
 
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
Línea 27... Línea 17...
27
 */
17
namespace core_cache;
-
 
18
 
Línea 28... Línea 19...
28
 
19
use core\exception\coding_exception;
29
defined('MOODLE_INTERNAL') || die();
20
use lang_string;
30
 
21
 
31
/**
22
/**
32
 * The cache definition class.
23
 * The cache definition class.
33
 *
24
 *
34
 * Cache definitions need to be defined in db/caches.php files.
25
 * Cache definitions need to be defined in db/caches.php files.
35
 * They can be constructed with the following options.
26
 * They can be constructed with the following options.
36
 *
27
 *
37
 * Required settings:
28
 * Required settings:
38
 *     + mode
29
 *     + mode
39
 *          [int] Sets the mode for the definition. Must be one of cache_store::MODE_*
30
 *          [int] Sets the mode for the definition. Must be one of store::MODE_*
40
 *
31
 *
41
 * Optional settings:
32
 * Optional settings:
Línea 59... Línea 50...
59
 *          [int] If set this will be used as the maximum number of entries within the cache store for this definition.
50
 *          [int] If set this will be used as the maximum number of entries within the cache store for this definition.
60
 *          Its important to note that cache stores don't actually have to acknowledge this setting or maintain it as a hard limit.
51
 *          Its important to note that cache stores don't actually have to acknowledge this setting or maintain it as a hard limit.
61
 *     + overrideclass
52
 *     + overrideclass
62
 *          [string] A class to use as the loader for this cache. This is an advanced setting and will allow the developer of the
53
 *          [string] A class to use as the loader for this cache. This is an advanced setting and will allow the developer of the
63
 *          definition to take 100% control of the caching solution.
54
 *          definition to take 100% control of the caching solution.
64
 *          Any class used here must inherit the cache_loader interface and must extend default cache loader for the mode they are
55
 *          Any class used here must inherit the cache loader_interface and must extend default cache loader for the mode they are
65
 *          using.
56
 *          using.
66
 *     + overrideclassfile
57
 *     + overrideclassfile
67
 *          [string] Suplements the above setting indicated the file containing the class to be used. This file is included when
58
 *          [string] Suplements the above setting indicated the file containing the class to be used. This file is included when
68
 *          required.
59
 *          required.
69
 *     + datasource
60
 *     + datasource
70
 *          [string] A class to use as the data loader for this definition.
61
 *          [string] A class to use as the data loader for this definition.
71
 *          Any class used here must inherit the cache_data_loader interface.
62
 *          Any class used here must inherit the \core_cache\data_source_interface interface.
72
 *     + datasourcefile
63
 *     + datasourcefile
73
 *          [string] Supplements the above setting indicating the file containing the class to be used. This file is included when
64
 *          [string] Supplements the above setting indicating the file containing the class to be used. This file is included when
74
 *          required.
65
 *          required.
75
 *     + staticacceleration
66
 *     + staticacceleration
76
 *          The cache loader will keep an array of the items set and retrieved to the cache during the request.
67
 *          The cache loader will keep an array of the items set and retrieved to the cache during the request.
Línea 101... Línea 92...
101
 *                 system as seen in modinfo cache or language cache.  Requiring purge on upgrade is not sufficient as
92
 *                 system as seen in modinfo cache or language cache.  Requiring purge on upgrade is not sufficient as
102
 *                 it requires administrator intervention on each node to make it work.
93
 *                 it requires administrator intervention on each node to make it work.
103
 *
94
 *
104
 * For examples take a look at lib/db/caches.php
95
 * For examples take a look at lib/db/caches.php
105
 *
96
 *
106
 * @package    core
97
 * @package    core_cache
107
 * @category   cache
98
 * @category   cache
108
 * @copyright  2012 Sam Hemelryk
99
 * @copyright  2012 Sam Hemelryk
109
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
100
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
110
 */
101
 */
111
class cache_definition {
102
class definition {
112
 
-
 
113
    /** The cache can be shared with everyone */
103
    /** The cache can be shared with everyone */
114
    const SHARING_ALL = 1;
104
    const SHARING_ALL = 1;
115
    /** The cache can be shared with other sites using the same siteid. */
105
    /** The cache can be shared with other sites using the same siteid. */
116
    const SHARING_SITEID = 2;
106
    const SHARING_SITEID = 2;
117
    /** The cache can be shared with other sites of the same version. */
107
    /** The cache can be shared with other sites of the same version. */
Línea 135... Línea 125...
135
     * @var string
125
     * @var string
136
     */
126
     */
137
    protected $id;
127
    protected $id;
Línea 138... Línea 128...
138
 
128
 
139
    /**
129
    /**
140
     * The mode for the defintion. One of cache_store::MODE_*
130
     * The mode for the defintion. One of store::MODE_*
141
     * @var int
131
     * @var int
142
     */
132
     */
Línea 143... Línea 133...
143
    protected $mode;
133
    protected $mode;
Línea 168... Línea 158...
168
 
158
 
169
    /**
159
    /**
170
     * An array of identifiers that must be provided when the definition is used to create a cache.
160
     * An array of identifiers that must be provided when the definition is used to create a cache.
171
     * @var array
161
     * @var array
172
     */
162
     */
Línea 173... Línea 163...
173
    protected $requireidentifiers = array();
163
    protected $requireidentifiers = [];
174
 
164
 
175
    /**
165
    /**
176
     * If set to true then only stores that guarantee data may be used with this definition.
166
     * If set to true then only stores that guarantee data may be used with this definition.
Línea 261... Línea 251...
261
 
251
 
262
    /**
252
    /**
263
     * An array of events that should cause this cache to invalidate.
253
     * An array of events that should cause this cache to invalidate.
264
     * @var array
254
     * @var array
265
     */
255
     */
Línea 266... Línea 256...
266
    protected $invalidationevents = array();
256
    protected $invalidationevents = [];
267
 
257
 
268
    /**
258
    /**
269
     * An array of identifiers provided to this cache when it was initialised.
259
     * An array of identifiers provided to this cache when it was initialised.
Línea 317... Línea 307...
317
     * Creates a cache definition given a definition from the cache configuration or from a caches.php file.
307
     * Creates a cache definition given a definition from the cache configuration or from a caches.php file.
318
     *
308
     *
319
     * @param string $id
309
     * @param string $id
320
     * @param array $definition
310
     * @param array $definition
321
     * @param string $unused Used to be datasourceaggregate but that was removed and this is now unused.
311
     * @param string $unused Used to be datasourceaggregate but that was removed and this is now unused.
322
     * @return cache_definition
312
     * @return definition
323
     * @throws coding_exception
313
     * @throws coding_exception
324
     */
314
     */
325
    public static function load($id, array $definition, $unused = null) {
315
    public static function load($id, array $definition, $unused = null) {
326
        global $CFG;
316
        global $CFG;
Línea 339... Línea 329...
339
        $area = (string)$definition['area'];
329
        $area = (string)$definition['area'];
Línea 340... Línea 330...
340
 
330
 
341
        // Set the defaults.
331
        // Set the defaults.
342
        $simplekeys = false;
332
        $simplekeys = false;
343
        $simpledata = false;
333
        $simpledata = false;
344
        $requireidentifiers = array();
334
        $requireidentifiers = [];
345
        $requiredataguarantee = false;
335
        $requiredataguarantee = false;
346
        $requiremultipleidentifiers = false;
336
        $requiremultipleidentifiers = false;
347
        $requirelockingbeforewrite = false;
337
        $requirelockingbeforewrite = false;
348
        $requiresearchable = ($mode === cache_store::MODE_SESSION) ? true : false;
338
        $requiresearchable = ($mode === store::MODE_SESSION) ? true : false;
349
        $maxsize = null;
339
        $maxsize = null;
350
        $overrideclass = null;
340
        $overrideclass = null;
351
        $overrideclassfile = null;
341
        $overrideclassfile = null;
352
        $datasource = null;
342
        $datasource = null;
353
        $datasourcefile = null;
343
        $datasourcefile = null;
354
        $staticacceleration = false;
344
        $staticacceleration = false;
355
        $staticaccelerationsize = false;
345
        $staticaccelerationsize = false;
356
        $ttl = 0;
346
        $ttl = 0;
357
        $mappingsonly = false;
347
        $mappingsonly = false;
358
        $invalidationevents = array();
348
        $invalidationevents = [];
359
        $sharingoptions = self::SHARING_DEFAULT;
349
        $sharingoptions = self::SHARING_DEFAULT;
360
        $selectedsharingoption = self::SHARING_DEFAULT;
350
        $selectedsharingoption = self::SHARING_DEFAULT;
361
        $userinputsharingkey = '';
351
        $userinputsharingkey = '';
Línea 376... Línea 366...
376
        if (array_key_exists('requiremultipleidentifiers', $definition)) {
366
        if (array_key_exists('requiremultipleidentifiers', $definition)) {
377
            $requiremultipleidentifiers = (bool)$definition['requiremultipleidentifiers'];
367
            $requiremultipleidentifiers = (bool)$definition['requiremultipleidentifiers'];
378
        }
368
        }
Línea 379... Línea 369...
379
 
369
 
-
 
370
        if (array_key_exists('requirelockingread', $definition)) {
380
        if (array_key_exists('requirelockingread', $definition)) {
371
            debugging(
381
            debugging('The cache option requirelockingread is deprecated and now has no effect.',
372
                'The cache option requirelockingread is deprecated and now has no effect.',
-
 
373
                DEBUG_DEVELOPER
382
                    DEBUG_DEVELOPER);
374
            );
383
        }
375
        }
-
 
376
        if (array_key_exists('requirelockingwrite', $definition)) {
384
        if (array_key_exists('requirelockingwrite', $definition)) {
377
            debugging(
385
            debugging('The cache option requirelockingwrite is deprecated and now has no effect. ' .
378
                'The cache option requirelockingwrite is deprecated and now has no effect. ' .
386
                    "Consider removing the option, or using requirelockingbeforewrite for the $component:$area definition",
379
                    "Consider removing the option, or using requirelockingbeforewrite for the $component:$area definition",
-
 
380
                DEBUG_DEVELOPER
387
                    DEBUG_DEVELOPER);
381
            );
388
        }
382
        }
389
        if (array_key_exists('requirelockingbeforewrite', $definition)) {
383
        if (array_key_exists('requirelockingbeforewrite', $definition)) {
390
            $requirelockingbeforewrite = (bool)$definition['requirelockingbeforewrite'];
384
            $requirelockingbeforewrite = (bool)$definition['requirelockingbeforewrite'];
391
        }
385
        }
Línea 463... Línea 457...
463
        }
457
        }
Línea 464... Línea 458...
464
 
458
 
465
        if (!is_null($overrideclass)) {
459
        if (!is_null($overrideclass)) {
466
            if (!is_null($overrideclassfile)) {
460
            if (!is_null($overrideclassfile)) {
467
                if (strpos($overrideclassfile, $CFG->dirroot) !== 0) {
461
                if (strpos($overrideclassfile, $CFG->dirroot) !== 0) {
468
                    $overrideclassfile = $CFG->dirroot.'/'.$overrideclassfile;
462
                    $overrideclassfile = $CFG->dirroot . '/' . $overrideclassfile;
469
                }
463
                }
470
                if (strpos($overrideclassfile, '../') !== false) {
464
                if (strpos($overrideclassfile, '../') !== false) {
471
                    throw new coding_exception('No path craziness allowed within override class file path.');
465
                    throw new coding_exception('No path craziness allowed within override class file path.');
472
                }
466
                }
Línea 478... Línea 472...
478
            if (!class_exists($overrideclass)) {
472
            if (!class_exists($overrideclass)) {
479
                throw new coding_exception('The override class does not exist.');
473
                throw new coding_exception('The override class does not exist.');
480
            }
474
            }
Línea 481... Línea 475...
481
 
475
 
482
            // Make sure that the provided class extends the default class for the mode.
476
            // Make sure that the provided class extends the default class for the mode.
483
            if (get_parent_class($overrideclass) !== cache_helper::get_class_for_mode($mode)) {
477
            if (get_parent_class($overrideclass) !== helper::get_class_for_mode($mode)) {
484
                throw new coding_exception('The override class does not immediately extend the relevant cache class.');
478
                throw new coding_exception('The override class does not immediately extend the relevant cache class.');
485
            }
479
            }
Línea 486... Línea 480...
486
        }
480
        }
487
 
481
 
488
        if (!is_null($datasource)) {
482
        if (!is_null($datasource)) {
489
            if (!is_null($datasourcefile)) {
483
            if (!is_null($datasourcefile)) {
490
                if (strpos($datasourcefile, $CFG->dirroot) !== 0) {
484
                if (strpos($datasourcefile, $CFG->dirroot) !== 0) {
491
                    $datasourcefile = $CFG->dirroot.'/'.$datasourcefile;
485
                    $datasourcefile = $CFG->dirroot . '/' . $datasourcefile;
492
                }
486
                }
493
                if (strpos($datasourcefile, '../') !== false) {
487
                if (strpos($datasourcefile, '../') !== false) {
494
                    throw new coding_exception('No path craziness allowed within data source file path.');
488
                    throw new coding_exception('No path craziness allowed within data source file path.');
Línea 499... Línea 493...
499
                require_once($datasourcefile);
493
                require_once($datasourcefile);
500
            }
494
            }
501
            if (!class_exists($datasource)) {
495
            if (!class_exists($datasource)) {
502
                throw new coding_exception('The data source class does not exist.');
496
                throw new coding_exception('The data source class does not exist.');
503
            }
497
            }
504
            if (!array_key_exists('cache_data_source', class_implements($datasource))) {
498
            if (!is_a($datasource, data_source_interface::class, true)) {
505
                throw new coding_exception('Cache data source classes must implement the cache_data_source interface');
499
                throw new coding_exception('Cache data source classes must implement the data_source_interface interface');
506
            }
500
            }
507
        }
501
        }
Línea 508... Línea 502...
508
 
502
 
509
        $cachedefinition = new cache_definition();
503
        $cachedefinition = new self();
510
        $cachedefinition->id = $id;
504
        $cachedefinition->id = $id;
511
        $cachedefinition->mode = $mode;
505
        $cachedefinition->mode = $mode;
512
        $cachedefinition->component = $component;
506
        $cachedefinition->component = $component;
513
        $cachedefinition->area = $area;
507
        $cachedefinition->area = $area;
Línea 541... Línea 535...
541
     * Creates an ah-hoc cache definition given the required params.
535
     * Creates an ah-hoc cache definition given the required params.
542
     *
536
     *
543
     * Please note that when using an adhoc definition you cannot set any of the optional params.
537
     * Please note that when using an adhoc definition you cannot set any of the optional params.
544
     * This is because we cannot guarantee consistent access and we don't want to mislead people into thinking that.
538
     * This is because we cannot guarantee consistent access and we don't want to mislead people into thinking that.
545
     *
539
     *
546
     * @param int $mode One of cache_store::MODE_*
540
     * @param int $mode One of store::MODE_*
547
     * @param string $component The component this definition relates to.
541
     * @param string $component The component this definition relates to.
548
     * @param string $area The area this definition relates to.
542
     * @param string $area The area this definition relates to.
549
     * @param array $options An array of options, available options are:
543
     * @param array $options An array of options, available options are:
550
     *   - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_
544
     *   - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_
551
     *   - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars
545
     *   - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars
552
     *   - overrideclass : The class to use as the loader.
546
     *   - overrideclass : The class to use as the loader.
553
     *   - staticacceleration : If set to true the cache will hold onto data passing through it.
547
     *   - staticacceleration : If set to true the cache will hold onto data passing through it.
554
     *   - staticaccelerationsize : Set it to an int to limit the size of the staticacceleration cache.
548
     *   - staticaccelerationsize : Set it to an int to limit the size of the staticacceleration cache.
555
     * @return cache_application|cache_session|cache_request
549
     * @return self
556
     */
550
     */
557
    public static function load_adhoc($mode, $component, $area, array $options = array()) {
551
    public static function load_adhoc($mode, $component, $area, array $options = []) {
558
        $id = 'adhoc/'.$component.'_'.$area;
552
        $id = 'adhoc/' . $component . '_' . $area;
559
        $definition = array(
553
        $definition = [
560
            'mode' => $mode,
554
            'mode' => $mode,
561
            'component' => $component,
555
            'component' => $component,
562
            'area' => $area,
556
            'area' => $area,
563
        );
557
        ];
564
        if (!empty($options['simplekeys'])) {
558
        if (!empty($options['simplekeys'])) {
565
            $definition['simplekeys'] = $options['simplekeys'];
559
            $definition['simplekeys'] = $options['simplekeys'];
566
        }
560
        }
567
        if (!empty($options['simpledata'])) {
561
        if (!empty($options['simpledata'])) {
568
            $definition['simpledata'] = $options['simpledata'];
562
            $definition['simpledata'] = $options['simpledata'];
Línea 592... Línea 586...
592
     */
586
     */
593
    public function get_cache_class() {
587
    public function get_cache_class() {
594
        if (!is_null($this->overrideclass)) {
588
        if (!is_null($this->overrideclass)) {
595
            return $this->overrideclass;
589
            return $this->overrideclass;
596
        }
590
        }
597
        return cache_helper::get_class_for_mode($this->mode);
591
        return helper::get_class_for_mode($this->mode);
598
    }
592
    }
Línea 599... Línea 593...
599
 
593
 
600
    /**
594
    /**
601
     * Returns the id of this definition.
595
     * Returns the id of this definition.
Línea 608... Línea 602...
608
    /**
602
    /**
609
     * Returns the name for this definition
603
     * Returns the name for this definition
610
     * @return string
604
     * @return string
611
     */
605
     */
612
    public function get_name() {
606
    public function get_name() {
613
        $identifier = 'cachedef_'.clean_param($this->area, PARAM_STRINGID);
607
        $identifier = 'cachedef_' . clean_param($this->area, PARAM_STRINGID);
614
        $component = $this->component;
608
        $component = $this->component;
615
        if ($component === 'core') {
609
        if ($component === 'core') {
616
            $component = 'cache';
610
            $component = 'cache';
617
        }
611
        }
618
        return new lang_string($identifier, $component);
612
        return new lang_string($identifier, $component);
619
    }
613
    }
Línea 620... Línea 614...
620
 
614
 
621
    /**
615
    /**
622
     * Returns the mode of this definition
616
     * Returns the mode of this definition
623
     * @return int One more cache_store::MODE_
617
     * @return int One more store::MODE_
624
     */
618
     */
625
    public function get_mode() {
619
    public function get_mode() {
626
        return $this->mode;
620
        return $this->mode;
Línea 657... Línea 651...
657
     * Returns the identifiers that are being used for this definition.
651
     * Returns the identifiers that are being used for this definition.
658
     * @return array
652
     * @return array
659
     */
653
     */
660
    public function get_identifiers() {
654
    public function get_identifiers() {
661
        if (!isset($this->identifiers)) {
655
        if (!isset($this->identifiers)) {
662
            return array();
656
            return [];
663
        }
657
        }
664
        return $this->identifiers;
658
        return $this->identifiers;
665
    }
659
    }
Línea 666... Línea 660...
666
 
660
 
Línea 755... Línea 749...
755
    }
749
    }
Línea 756... Línea 750...
756
 
750
 
757
    /**
751
    /**
758
     * Returns an instance of the data source class used for this definition.
752
     * Returns an instance of the data source class used for this definition.
759
     *
753
     *
760
     * @return cache_data_source
754
     * @return data_source_interface
761
     * @throws coding_exception
755
     * @throws coding_exception
762
     */
756
     */
763
    public function get_data_source() {
757
    public function get_data_source() {
764
        if (!$this->has_data_source()) {
758
        if (!$this->has_data_source()) {
765
            throw new coding_exception('This cache does not use a data source.');
759
            throw new coding_exception('This cache does not use a data source.');
766
        }
760
        }
767
        return forward_static_call(array($this->datasource, 'get_instance_for_cache'), $this);
761
        return forward_static_call([$this->datasource, 'get_instance_for_cache'], $this);
Línea 768... Línea 762...
768
    }
762
    }
769
 
763
 
770
    /**
764
    /**
771
     * Sets the identifiers for this definition, or updates them if they have already been set.
765
     * Sets the identifiers for this definition, or updates them if they have already been set.
772
     *
766
     *
773
     * @param array $identifiers
767
     * @param array $identifiers
774
     * @return bool false if no identifiers where changed, true otherwise.
768
     * @return bool false if no identifiers where changed, true otherwise.
775
     * @throws coding_exception
769
     * @throws coding_exception
776
     */
770
     */
777
    public function set_identifiers(array $identifiers = array()) {
771
    public function set_identifiers(array $identifiers = []) {
778
        if ($this->identifiers !== null) {
772
        if ($this->identifiers !== null) {
779
            throw new coding_exception("You can only set identifiers on initial definition creation." .
773
            throw new coding_exception("You can only set identifiers on initial definition creation." .
780
                " Define a new cache to set different identifiers.");
774
                " Define a new cache to set different identifiers.");
781
        }
775
        }
782
        if (!empty($identifiers) && !empty($this->invalidationevents)) {
776
        if (!empty($identifiers) && !empty($this->invalidationevents)) {
Línea 783... Línea 777...
783
            throw new coding_exception("You cannot use event invalidation and identifiers at the same time.");
777
            throw new coding_exception("You cannot use event invalidation and identifiers at the same time.");
784
        }
778
        }
785
 
779
 
786
        foreach ($this->requireidentifiers as $identifier) {
780
        foreach ($this->requireidentifiers as $identifier) {
787
            if (!isset($identifiers[$identifier])) {
781
            if (!isset($identifiers[$identifier])) {
Línea 788... Línea 782...
788
                throw new coding_exception('Identifier required for cache has not been provided: '.$identifier);
782
                throw new coding_exception('Identifier required for cache has not been provided: ' . $identifier);
Línea 789... Línea 783...
789
            }
783
            }
790
        }
784
        }
791
 
785
 
792
        $this->identifiers = array();
786
        $this->identifiers = [];
Línea 806... Línea 800...
806
     * @return int
800
     * @return int
807
     */
801
     */
808
    public function get_requirements_bin() {
802
    public function get_requirements_bin() {
809
        $requires = 0;
803
        $requires = 0;
810
        if ($this->require_data_guarantee()) {
804
        if ($this->require_data_guarantee()) {
811
            $requires += cache_store::SUPPORTS_DATA_GUARANTEE;
805
            $requires += store::SUPPORTS_DATA_GUARANTEE;
812
        }
806
        }
813
        if ($this->require_multiple_identifiers()) {
807
        if ($this->require_multiple_identifiers()) {
814
            $requires += cache_store::SUPPORTS_MULTIPLE_IDENTIFIERS;
808
            $requires += store::SUPPORTS_MULTIPLE_IDENTIFIERS;
815
        }
809
        }
816
        if ($this->require_searchable()) {
810
        if ($this->require_searchable()) {
817
            $requires += cache_store::IS_SEARCHABLE;
811
            $requires += store::IS_SEARCHABLE;
818
        }
812
        }
819
        return $requires;
813
        return $requires;
820
    }
814
    }
Línea 821... Línea 815...
821
 
815
 
822
    /**
-
 
823
     * Please call {@link cache_definition::use_static_acceleration()} instead.
-
 
824
     *
-
 
825
     * @see cache_definition::use_static_acceleration()
-
 
826
     * @deprecated since 2.6
-
 
827
     */
-
 
828
    public function should_be_persistent() {
-
 
829
        throw new coding_exception('cache_definition::should_be_persistent() can not be used anymore.' .
-
 
830
            ' Please use cache_definition::use_static_acceleration() instead.');
-
 
831
    }
-
 
832
 
-
 
833
    /**
816
    /**
834
     * Returns true if we should hold onto the data flowing through the cache.
817
     * Returns true if we should hold onto the data flowing through the cache.
835
     *
818
     *
836
     * If set to true data flowing through the cache will be stored in a static variable
819
     * If set to true data flowing through the cache will be stored in a static variable
837
     * to make subsequent requests for the data much faster.
820
     * to make subsequent requests for the data much faster.
838
     *
821
     *
839
     * @return bool
822
     * @return bool
840
     */
823
     */
841
    public function use_static_acceleration() {
824
    public function use_static_acceleration() {
842
        if ($this->mode === cache_store::MODE_REQUEST) {
825
        if ($this->mode === store::MODE_REQUEST) {
843
            // Request caches should never use static acceleration - it just doesn't make sense.
826
            // Request caches should never use static acceleration - it just doesn't make sense.
844
            return false;
827
            return false;
845
        }
828
        }
846
        return $this->staticacceleration;
829
        return $this->staticacceleration;
Línea 847... Línea 830...
847
    }
830
    }
848
 
-
 
849
    /**
-
 
850
     * Please call {@link cache_definition::get_static_acceleration_size()} instead.
-
 
851
     *
-
 
852
     * @see cache_definition::get_static_acceleration_size()
-
 
853
     * @deprecated since 2.6
-
 
854
     */
-
 
855
    public function get_persistent_max_size() {
-
 
856
        throw new coding_exception('cache_definition::get_persistent_max_size() can not be used anymore.' .
-
 
857
            ' Please use cache_definition::get_static_acceleration_size() instead.');
-
 
858
    }
-
 
859
 
831
 
860
    /**
832
    /**
861
     * Returns the max size for the static acceleration array.
833
     * Returns the max size for the static acceleration array.
862
     * @return int
834
     * @return int
863
     */
835
     */
Línea 881... Línea 853...
881
     *
853
     *
882
     * @return string
854
     * @return string
883
     */
855
     */
884
    public function generate_single_key_prefix() {
856
    public function generate_single_key_prefix() {
885
        if ($this->keyprefixsingle === null) {
857
        if ($this->keyprefixsingle === null) {
886
            $this->keyprefixsingle = $this->mode.'/'.$this->component.'/'.$this->area;
858
            $this->keyprefixsingle = $this->mode . '/' . $this->component . '/' . $this->area;
887
            $this->keyprefixsingle .= '/'.$this->get_cache_identifier();
859
            $this->keyprefixsingle .= '/' . $this->get_cache_identifier();
888
            $identifiers = $this->get_identifiers();
860
            $identifiers = $this->get_identifiers();
889
            if ($identifiers) {
861
            if ($identifiers) {
890
                foreach ($identifiers as $key => $value) {
862
                foreach ($identifiers as $key => $value) {
891
                    $this->keyprefixsingle .= '/'.$key.'='.$value;
863
                    $this->keyprefixsingle .= '/' . $key . '=' . $value;
892
                }
864
                }
893
            }
865
            }
894
            $this->keyprefixsingle = md5($this->keyprefixsingle);
866
            $this->keyprefixsingle = md5($this->keyprefixsingle);
895
        }
867
        }
896
        return $this->keyprefixsingle;
868
        return $this->keyprefixsingle;
Línea 901... Línea 873...
901
     *
873
     *
902
     * @return array
874
     * @return array
903
     */
875
     */
904
    public function generate_multi_key_parts() {
876
    public function generate_multi_key_parts() {
905
        if ($this->keyprefixmulti === null) {
877
        if ($this->keyprefixmulti === null) {
906
            $this->keyprefixmulti = array(
878
            $this->keyprefixmulti = [
907
                'mode' => $this->mode,
879
                'mode' => $this->mode,
908
                'component' => $this->component,
880
                'component' => $this->component,
909
                'area' => $this->area,
881
                'area' => $this->area,
910
                'siteidentifier' => $this->get_cache_identifier()
882
                'siteidentifier' => $this->get_cache_identifier(),
911
            );
883
            ];
912
            if (isset($this->identifiers) && !empty($this->identifiers)) {
884
            if (isset($this->identifiers) && !empty($this->identifiers)) {
913
                $identifiers = array();
885
                $identifiers = [];
914
                foreach ($this->identifiers as $key => $value) {
886
                foreach ($this->identifiers as $key => $value) {
915
                    $identifiers[] = htmlentities($key, ENT_QUOTES, 'UTF-8').'='.htmlentities($value, ENT_QUOTES, 'UTF-8');
887
                    $identifiers[] = htmlentities($key, ENT_QUOTES, 'UTF-8') . '=' . htmlentities($value, ENT_QUOTES, 'UTF-8');
916
                }
888
                }
917
                $this->keyprefixmulti['identifiers'] = join('&', $identifiers);
889
                $this->keyprefixmulti['identifiers'] = join('&', $identifiers);
918
            }
890
            }
919
        }
891
        }
920
        return $this->keyprefixmulti;
892
        return $this->keyprefixmulti;
Línea 952... Línea 924...
952
     * Returns a cache identification string.
924
     * Returns a cache identification string.
953
     *
925
     *
954
     * @return string A string to be used as part of keys.
926
     * @return string A string to be used as part of keys.
955
     */
927
     */
956
    protected function get_cache_identifier() {
928
    protected function get_cache_identifier() {
957
        $identifiers = array();
929
        $identifiers = [];
958
        if ($this->selectedsharingoption & self::SHARING_ALL) {
930
        if ($this->selectedsharingoption & self::SHARING_ALL) {
959
            // Nothing to do here.
931
            // Nothing to do here.
960
        } else {
932
        } else {
961
            if ($this->selectedsharingoption & self::SHARING_SITEID) {
933
            if ($this->selectedsharingoption & self::SHARING_SITEID) {
962
                $identifiers[] = cache_helper::get_site_identifier();
934
                $identifiers[] = helper::get_site_identifier();
963
            }
935
            }
964
            if ($this->selectedsharingoption & self::SHARING_VERSION) {
936
            if ($this->selectedsharingoption & self::SHARING_VERSION) {
965
                $identifiers[] = cache_helper::get_site_version();
937
                $identifiers[] = helper::get_site_version();
966
            }
938
            }
967
            if ($this->selectedsharingoption & self::SHARING_INPUT && !empty($this->userinputsharingkey)) {
939
            if ($this->selectedsharingoption & self::SHARING_INPUT && !empty($this->userinputsharingkey)) {
968
                $identifiers[] = $this->userinputsharingkey;
940
                $identifiers[] = $this->userinputsharingkey;
969
            }
941
            }
970
        }
942
        }
Línea 1005... Línea 977...
1005
     */
977
     */
1006
    public function get_selected_sharing_option() {
978
    public function get_selected_sharing_option() {
1007
        return $this->selectedsharingoption;
979
        return $this->selectedsharingoption;
1008
    }
980
    }
1009
}
981
}
-
 
982
 
-
 
983
// Alias this class to the old name.
-
 
984
// This file will be autoloaded by the legacyclasses autoload system.
-
 
985
// In future all uses of this class will be corrected and the legacy references will be removed.
-
 
986
class_alias(definition::class, \cache_definition::class);