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: locking.
|
|
|
21 |
*
|
|
|
22 |
* This is a feature that cache stores can implement if they wish to support locking themselves rather
|
|
|
23 |
* than having the cache loader handle it for them.
|
|
|
24 |
*
|
|
|
25 |
* Can be implemented by classes already implementing store.
|
|
|
26 |
* @package core_cache
|
|
|
27 |
* @copyright Sam Hemelryk
|
|
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
29 |
*/
|
|
|
30 |
interface lockable_cache_interface {
|
|
|
31 |
/**
|
|
|
32 |
* Acquires a lock on the given key for the given identifier.
|
|
|
33 |
*
|
|
|
34 |
* @param string $key The key we are locking.
|
|
|
35 |
* @param string $ownerid The identifier so we can check if we have the lock or if it is someone else.
|
|
|
36 |
* The use of this property is entirely optional and implementations can act as they like upon it.
|
|
|
37 |
* @return bool True if the lock could be acquired, false otherwise.
|
|
|
38 |
*/
|
|
|
39 |
public function acquire_lock($key, $ownerid);
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Test if there is already a lock for the given key and if there is whether it belongs to the calling code.
|
|
|
43 |
*
|
|
|
44 |
* @param string $key The key we are locking.
|
|
|
45 |
* @param string $ownerid The identifier so we can check if we have the lock or if it is someone else.
|
|
|
46 |
* @return bool True if this code has the lock, false if there is a lock but this code doesn't have it, null if there
|
|
|
47 |
* is no lock.
|
|
|
48 |
*/
|
|
|
49 |
public function check_lock_state($key, $ownerid);
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Releases the lock on the given key.
|
|
|
53 |
*
|
|
|
54 |
* @param string $key The key we are locking.
|
|
|
55 |
* @param string $ownerid The identifier so we can check if we have the lock or if it is someone else.
|
|
|
56 |
* The use of this property is entirely optional and implementations can act as they like upon it.
|
|
|
57 |
* @return bool True if the lock has been released, false if there was a problem releasing the lock.
|
|
|
58 |
*/
|
|
|
59 |
public function release_lock($key, $ownerid);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
// Alias this class to the old name.
|
|
|
63 |
// This file will be autoloaded by the legacyclasses autoload system.
|
|
|
64 |
// In future all uses of this class will be corrected and the legacy references will be removed.
|
|
|
65 |
class_alias(lockable_cache_interface::class, \cache_is_lockable::class);
|