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 store - base class
-
 
19
 *
-
 
20
 * This file is part of Moodle's cache API, affectionately called MUC.
-
 
21
 * It contains the components that are required 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
-
 
27
 */
-
 
28
 
-
 
29
defined('MOODLE_INTERNAL') || die();
-
 
30
 
-
 
31
/**
-
 
32
 * Cache store interface.
-
 
33
 *
-
 
34
 * This interface defines the static methods that must be implemented by every cache store plugin.
-
 
35
 * To ensure plugins implement this class the abstract cache_store class implements this interface.
-
 
36
 *
-
 
37
 * @package    core
-
 
38
 * @category   cache
-
 
39
 * @copyright  2012 Sam Hemelryk
-
 
40
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
41
 */
-
 
42
interface cache_store_interface {
-
 
43
    /**
-
 
44
     * Static method to check if the store requirements are met.
-
 
45
     *
-
 
46
     * @return bool True if the stores software/hardware requirements have been met and it can be used. False otherwise.
-
 
47
     */
-
 
48
    public static function are_requirements_met();
-
 
49
 
-
 
50
    /**
-
 
51
     * Static method to check if a store is usable with the given mode.
-
 
52
     *
-
 
53
     * @param int $mode One of cache_store::MODE_*
-
 
54
     */
-
 
Línea 55... Línea -...
55
    public static function is_supported_mode($mode);
-
 
56
 
-
 
57
    /**
-
 
58
     * Returns the supported features as a binary flag.
-
 
59
     *
-
 
60
     * @param array $configuration The configuration of a store to consider specifically.
-
 
61
     * @return int The supported features.
-
 
62
     */
-
 
63
    public static function get_supported_features(array $configuration = array());
-
 
64
 
-
 
65
    /**
-
 
66
     * Returns the supported modes as a binary flag.
-
 
67
     *
-
 
68
     * @param array $configuration The configuration of a store to consider specifically.
-
 
69
     * @return int The supported modes.
-
 
70
     */
-
 
71
    public static function get_supported_modes(array $configuration = array());
-
 
72
 
-
 
73
    /**
-
 
74
     * Generates an instance of the cache store that can be used for testing.
-
 
75
     *
-
 
76
     * Returns an instance of the cache store, or false if one cannot be created.
17
namespace core_cache;
77
     *
-
 
78
     * @param cache_definition $definition
-
 
79
     * @return cache_store|false
-
 
80
     */
-
 
81
    public static function initialise_test_instance(cache_definition $definition);
-
 
82
 
-
 
83
    /**
-
 
84
     * Generates the appropriate configuration required for unit testing.
-
 
85
     *
18
 
86
     * @return array Array of unit test configuration data to be used by initialise().
-
 
87
     */
-
 
Línea 88... Línea 19...
88
    public static function unit_test_configuration();
19
use core\exception\coding_exception;
89
}
20
use stdClass;
90
 
21
 
91
/**
22
/**
92
 * Abstract cache store class.
23
 * Abstract cache store class.
93
 *
24
 *
94
 * All cache store plugins must extend this base class.
25
 * All cache store plugins must extend this base class.
95
 * It lays down the foundation for what is required of a cache store plugin.
26
 * It lays down the foundation for what is required of a cache store plugin.
96
 *
27
 *
97
 * @since Moodle 2.4
28
 * @since Moodle 2.4
98
 * @package    core
29
 * @package    core_cache
99
 * @category   cache
30
 * @category   cache
100
 * @copyright  2012 Sam Hemelryk
31
 * @copyright  2012 Sam Hemelryk
101
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
102
 */
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Línea 103... Línea 33...
103
abstract class cache_store implements cache_store_interface {
33
 */
104
 
34
abstract class store implements store_interface {
105
    // Constants for features a cache store can support
35
    // Constants for features a cache store can support
Línea 169... Línea 99...
169
     * that method should return false so that the store instance is not selected for use.
99
     * that method should return false so that the store instance is not selected for use.
170
     *
100
     *
171
     * @param string $name The name of the cache store
101
     * @param string $name The name of the cache store
172
     * @param array $configuration The configuration for this store instance.
102
     * @param array $configuration The configuration for this store instance.
173
     */
103
     */
174
    abstract public function __construct($name, array $configuration = array());
104
    abstract public function __construct($name, array $configuration = []);
Línea 175... Línea 105...
175
 
105
 
176
    /**
106
    /**
177
     * Returns the name of this store instance.
107
     * Returns the name of this store instance.
178
     * @return string
108
     * @return string
Línea 187... Línea 117...
187
     *
117
     *
188
     * Its important to note that the initialise method is expected to always succeed.
118
     * Its important to note that the initialise method is expected to always succeed.
189
     * If there are setup tasks that may fail they should be done within the __construct method
119
     * If there are setup tasks that may fail they should be done within the __construct method
190
     * and should they fail is_ready should return false.
120
     * and should they fail is_ready should return false.
191
     *
121
     *
192
     * @param cache_definition $definition
122
     * @param definition $definition
193
     */
123
     */
194
    abstract public function initialise(cache_definition $definition);
124
    abstract public function initialise(definition $definition);
Línea 195... Línea 125...
195
 
125
 
196
    /**
126
    /**
197
     * Returns true if this cache store instance has been initialised.
127
     * Returns true if this cache store instance has been initialised.
198
     * @return bool
128
     * @return bool
Línea 202... Línea 132...
202
    /**
132
    /**
203
     * Returns true if this cache store instance is ready to use.
133
     * Returns true if this cache store instance is ready to use.
204
     * @return bool
134
     * @return bool
205
     */
135
     */
206
    public function is_ready() {
136
    public function is_ready() {
207
        return forward_static_call(array($this, 'are_requirements_met'));
137
        return forward_static_call([$this, 'are_requirements_met']);
208
    }
138
    }
Línea 209... Línea 139...
209
 
139
 
210
    /**
140
    /**
211
     * Retrieves an item from the cache store given its key.
141
     * Retrieves an item from the cache store given its key.
Línea 267... Línea 197...
267
     * @return boolean True on success. False otherwise.
197
     * @return boolean True on success. False otherwise.
268
     */
198
     */
269
    abstract public function purge();
199
    abstract public function purge();
Línea 270... Línea 200...
270
 
200
 
271
    /**
-
 
272
     * @deprecated since 2.5
-
 
273
     * @see \cache_store::instance_deleted()
-
 
274
     */
-
 
275
    public function cleanup() {
-
 
276
        throw new coding_exception('cache_store::cleanup() can not be used anymore.' .
-
 
277
            ' Please use cache_store::instance_deleted() instead.');
-
 
278
    }
-
 
279
 
-
 
280
    /**
201
    /**
281
     * Performs any necessary operation when the store instance has been created.
202
     * Performs any necessary operation when the store instance has been created.
282
     *
203
     *
283
     * @since Moodle 2.5
204
     * @since Moodle 2.5
284
     */
205
     */
Línea 342... Línea 263...
342
     * Returns true if the store instance is searchable.
263
     * Returns true if the store instance is searchable.
343
     *
264
     *
344
     * @return bool
265
     * @return bool
345
     */
266
     */
346
    public function is_searchable() {
267
    public function is_searchable() {
347
        return in_array('cache_is_searchable', class_implements($this));
268
        return ($this instanceof searchable_cache_interface);
348
    }
269
    }
Línea 349... Línea 270...
349
 
270
 
350
    /**
271
    /**
351
     * Returns true if the store automatically dereferences objects.
272
     * Returns true if the store automatically dereferences objects.
Línea 364... Línea 285...
364
     *
285
     *
365
     * If you are writing a cache store that isn't compatible with the clone operation
286
     * If you are writing a cache store that isn't compatible with the clone operation
366
     * you can override this method to handle any situations you want before cloning.
287
     * you can override this method to handle any situations you want before cloning.
367
     *
288
     *
368
     * @param array $details An array containing the details of the store from the cache config.
289
     * @param array $details An array containing the details of the store from the cache config.
369
     * @return cache_store
290
     * @return store
370
     */
291
     */
371
    public function create_clone(array $details = array()) {
292
    public function create_clone(array $details = []) {
372
        // By default we just run clone.
293
        // By default we just run clone.
373
        // Any stores that have an issue with this will need to override the create_clone method.
294
        // Any stores that have an issue with this will need to override the create_clone method.
374
        return clone($this);
295
        return clone($this);
375
    }
296
    }
Línea 381... Línea 302...
381
     * The warnings returned here will be displayed on the cache configuration screen.
302
     * The warnings returned here will be displayed on the cache configuration screen.
382
     *
303
     *
383
     * @return string[] An array of warning strings from the store instance.
304
     * @return string[] An array of warning strings from the store instance.
384
     */
305
     */
385
    public function get_warnings() {
306
    public function get_warnings() {
386
        return array();
307
        return [];
387
    }
308
    }
Línea 388... Línea 309...
388
 
309
 
389
    /**
310
    /**
390
     * Estimates the storage size used within this cache if the given value is stored with the
311
     * Estimates the storage size used within this cache if the given value is stored with the
Línea 444... Línea 365...
444
        $result = (object)[
365
        $result = (object)[
445
            'supported' => false,
366
            'supported' => false,
446
            'items' => 0,
367
            'items' => 0,
447
            'mean' => 0,
368
            'mean' => 0,
448
            'sd' => 0,
369
            'sd' => 0,
449
            'margin' => 0
370
            'margin' => 0,
450
        ];
371
        ];
Línea 451... Línea 372...
451
 
372
 
452
        // If this cache isn't searchable, we don't know the answer.
373
        // If this cache isn't searchable, we don't know the answer.
453
        if (!$this->is_searchable()) {
374
        if (!$this->is_searchable()) {
Línea 532... Línea 453...
532
     */
453
     */
533
    public function get_last_io_bytes(): int {
454
    public function get_last_io_bytes(): int {
534
        return self::IO_BYTES_NOT_SUPPORTED;
455
        return self::IO_BYTES_NOT_SUPPORTED;
535
    }
456
    }
536
}
457
}
-
 
458
 
-
 
459
// Alias this class to the old name.
-
 
460
// This file will be autoloaded by the legacyclasses autoload system.
-
 
461
// In future all uses of this class will be corrected and the legacy references will be removed.
-
 
462
class_alias(store::class, \cache_store::class);