3 * Cache of various elements in a single cache entry.
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.
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.
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
21 * @license GPL-2.0-or-later
22 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
26 * Interface for all classes implementing CacheHelper functionality.
30 interface ICacheHelper
{
32 * Sets if the cache should be enabled or not.
35 * @param bool $cacheEnabled
37 function setCacheEnabled( $cacheEnabled );
40 * Initializes the caching.
41 * Should be called before the first time anything is added via addCachedHTML.
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.
48 function startCache( $cacheExpiry = null, $cacheEnabled = null );
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.
58 * @param callable $computeFunction
59 * @param array|mixed $args
60 * @param string|null $key
64 function getCachedValue( $computeFunction, $args = [], $key = null );
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.
75 * Sets the time to live for the cache, in seconds or a unix timestamp
76 * indicating the point of expiry...
80 * @param int $cacheExpiry
82 function setExpiry( $cacheExpiry );