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 Data Source.
21
 *
22
 * The cache data source interface can be implemented by any class within Moodle.
23
 * If implemented then the class can be reference in a cache definition and will be used to load information that cannot be
24
 * retrieved from the cache. As part of its retrieval that information will also be loaded into the cache.
25
 *
26
 * This allows developers to created a complete cache solution that can be used through code ensuring consistent cache
27
 * interaction and loading. Allowing them in turn to centralise code and help keeps things more easily maintainable.
28
 *
29
 * Can be implemented by any class.
30
 *
31
 * @package    core_cache
32
 * @category   cache
33
 * @copyright  2012 Sam Hemelryk
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
interface data_source_interface {
37
    /**
38
     * Returns an instance of the data source class that the cache can use for loading data using the other methods
39
     * specified by this interface.
40
     *
41
     * @param definition $definition
42
     * @return object
43
     */
44
    public static function get_instance_for_cache(definition $definition);
45
 
46
    /**
47
     * Loads the data for the key provided ready formatted for caching.
48
     *
49
     * @param string|int $key The key to load.
50
     * @return mixed What ever data should be returned, or false if it can't be loaded.
51
     */
52
    public function load_for_cache($key);
53
 
54
    /**
55
     * Loads several keys for the cache.
56
     *
57
     * @param array $keys An array of keys each of which will be string|int.
58
     * @return array An array of matching data items.
59
     */
60
    public function load_many_for_cache(array $keys);
61
}
62
 
63
// Alias this class to the old name.
64
// This file will be autoloaded by the legacyclasses autoload system.
65
// In future all uses of this class will be corrected and the legacy references will be removed.
66
class_alias(data_source_interface::class, \cache_data_source::class);