Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
namespace core_cache;
18
 
19
/**
20
 * Cache store feature: key awareness.
21
 *
22
 * This is a feature that cache stores and cache loaders can both choose to implement.
23
 * If a cache store implements this then it will be made responsible for tests for items within the cache.
24
 * If the cache store being used doesn't implement this then it will be the responsibility of the cache loader to use the
25
 * equivalent get methods to mimick the functionality of these tests.
26
 *
27
 * Cache stores should only override these methods if they natively support such features or if they have a better performing
28
 * means of performing these tests than the handling that would otherwise take place in the cache_loader.
29
 *
30
 * Can be implemented by classes already implementing cache_store.
31
 *
32
 * @package core_cache
33
 * @copyright Sam Hemelryk
34
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
interface key_aware_cache_interface {
37
    /**
38
     * Test is a cache has a key.
39
     *
40
     * The use of the has methods is strongly discouraged. In a high load environment the cache may well change between the
41
     * test and any subsequent action (get, set, delete etc).
42
     * Instead it is recommended to write your code in such a way they it performs the following steps:
43
     * <ol>
44
     * <li>Attempt to retrieve the information.</li>
45
     * <li>Generate the information.</li>
46
     * <li>Attempt to set the information</li>
47
     * </ol>
48
     *
49
     * Its also worth mentioning that not all stores support key tests.
50
     * For stores that don't support key tests this functionality is mimicked by using the equivalent get method.
51
     * Just one more reason you should not use these methods unless you have a very good reason to do so.
52
     *
53
     * @param string|int $key
54
     * @return bool True if the cache has the requested key, false otherwise.
55
     */
56
    public function has($key);
57
 
58
    /**
59
     * Test if a cache has at least one of the given keys.
60
     *
61
     * It is strongly recommended to avoid the use of this function if not absolutely required.
62
     * In a high load environment the cache may well change between the test and any subsequent action (get, set, delete etc).
63
     *
64
     * Its also worth mentioning that not all stores support key tests.
65
     * For stores that don't support key tests this functionality is mimicked by using the equivalent get method.
66
     * Just one more reason you should not use these methods unless you have a very good reason to do so.
67
     *
68
     * @param array $keys
69
     * @return bool True if the cache has at least one of the given keys
70
     */
71
    public function has_any(array $keys);
72
 
73
    /**
74
     * Test is a cache has all of the given keys.
75
     *
76
     * It is strongly recommended to avoid the use of this function if not absolutely required.
77
     * In a high load environment the cache may well change between the test and any subsequent action (get, set, delete etc).
78
     *
79
     * Its also worth mentioning that not all stores support key tests.
80
     * For stores that don't support key tests this functionality is mimicked by using the equivalent get method.
81
     * Just one more reason you should not use these methods unless you have a very good reason to do so.
82
     *
83
     * @param array $keys
84
     * @return bool True if the cache has all of the given keys, false otherwise.
85
     */
86
    public function has_all(array $keys);
87
}
88
 
89
// Alias this class to the old name.
90
// This file will be autoloaded by the legacyclasses autoload system.
91
// In future all uses of this class will be corrected and the legacy references will be removed.
92
class_alias(key_aware_cache_interface::class, \cache_is_key_aware::class);