Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[lhc/web/wiklou.git] / includes / cache / ICacheHelper.php
1 <?php
2 /**
3 * Cache of various elements in a single cache entry.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @license GPL-2.0-or-later
22 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
23 */
24
25 /**
26 * Interface for all classes implementing CacheHelper functionality.
27 *
28 * @since 1.20
29 */
30 interface ICacheHelper {
31 /**
32 * Sets if the cache should be enabled or not.
33 *
34 * @since 1.20
35 * @param bool $cacheEnabled
36 */
37 function setCacheEnabled( $cacheEnabled );
38
39 /**
40 * Initializes the caching.
41 * Should be called before the first time anything is added via addCachedHTML.
42 *
43 * @since 1.20
44 *
45 * @param int|null $cacheExpiry Sets the cache expiry, either ttl in seconds or unix timestamp.
46 * @param bool|null $cacheEnabled Sets if the cache should be enabled or not.
47 */
48 function startCache( $cacheExpiry = null, $cacheEnabled = null );
49
50 /**
51 * Get a cached value if available or compute it if not and then cache it if possible.
52 * The provided $computeFunction is only called when the computation needs to happen
53 * and should return a result value. $args are arguments that will be passed to the
54 * compute function when called.
55 *
56 * @since 1.20
57 *
58 * @param callable $computeFunction
59 * @param array|mixed $args
60 * @param string|null $key
61 *
62 * @return mixed
63 */
64 function getCachedValue( $computeFunction, $args = [], $key = null );
65
66 /**
67 * Saves the HTML to the cache in case it got recomputed.
68 * Should be called after the last time anything is added via addCachedHTML.
69 *
70 * @since 1.20
71 */
72 function saveCache();
73
74 /**
75 * Sets the time to live for the cache, in seconds or a unix timestamp
76 * indicating the point of expiry...
77 *
78 * @since 1.20
79 *
80 * @param int $cacheExpiry
81 */
82 function setExpiry( $cacheExpiry );
83 }