3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 class CRM_Extension_BootCache
{
16 protected $locked = FALSE;
21 * Define a persistent value in the extension's boot-cache.
23 * This value is retained as part of the boot-cache. It will be loaded
24 * very quickly (eg via php op-code caching). However, as a trade-off,
25 * you will not be able to change/reset at runtime - it will only
26 * reset in response to a system-wide flush or redeployment.
28 * Ex: $mix->define('initTime', function() { return time(); });
31 * @param mixed $callback
33 * The value of $callback (either cached or fresh)
35 public function define($key, $callback) {
36 if (!isset($this->data
[$key])) {
37 $this->set($key, $callback($this));
39 return $this->data
[$key];
43 * Determine if $key has been set.
48 public function has($key) {
49 return isset($this->data
[$key]);
53 * Get the value of $key.
56 * @param mixed $default
59 public function get($key, $default = NULL) {
60 return $this->data
[$key] ??
$default;
64 * Set a value in the cache.
66 * This operation is only valid on the first page-load when a cache is built.
73 public function set($key, $value) {
75 throw new \
Exception("Cannot modify a locked boot-cache.");
77 $this->data
[$key] = $value;
81 public function lock() {