aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/StudipCacheFactory.class.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-11-06 09:47:33 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2024-11-06 17:09:49 +0100
commitba388f2b5d4d4bf18a28900cdfe29a2f059e360b (patch)
tree5e57050683c0ecae7554d1753fc6c4fc3b022ccd /lib/classes/StudipCacheFactory.class.php
parentc9b86019c2a32122ae15f0dc087f715e29eb0715 (diff)
allow cache settings to be configured even if caching is disabled, fixes #4806
Closes #4806 Merge request studip/studip!3597
Diffstat (limited to 'lib/classes/StudipCacheFactory.class.php')
-rw-r--r--lib/classes/StudipCacheFactory.class.php62
1 files changed, 36 insertions, 26 deletions
diff --git a/lib/classes/StudipCacheFactory.class.php b/lib/classes/StudipCacheFactory.class.php
index 77c5973..b934bda 100644
--- a/lib/classes/StudipCacheFactory.class.php
+++ b/lib/classes/StudipCacheFactory.class.php
@@ -81,34 +81,16 @@ class StudipCacheFactory
*/
public static function getCache($apply_proxied_operations = true)
{
- if (is_null(self::$cache)) {
- $proxied = false;
+ if (self::$cache === null) {
+ $proxied = !$GLOBALS['CACHING_ENABLE']
+ && isset($GLOBALS['GLOBAL_CACHING_ENABLE'])
+ && $GLOBALS['GLOBAL_CACHING_ENABLE'];
- if (!$GLOBALS['CACHING_ENABLE']) {
- self::$cache = new StudipMemoryCache();
+ self::$cache = self::loadSystemCache();
- // Proxy cache operations if CACHING_ENABLE is different from the globally set
- // caching value. This should only be the case in cli mode.
- if (isset($GLOBALS['GLOBAL_CACHING_ENABLE']) && $GLOBALS['GLOBAL_CACHING_ENABLE']) {
- $proxied = true;
- }
- } else {
- try {
- $class = self::loadCacheClass();
- $args = self::retrieveConstructorArguments();
-
- self::$cache = self::instantiateCache($class, $args);
- } catch (Exception $e) {
- error_log(__METHOD__ . ': ' . $e->getMessage());
- PageLayout::addBodyElements(MessageBox::error(__METHOD__ . ': ' . $e->getMessage()));
- $class = self::DEFAULT_CACHE_CLASS;
- self::$cache = new $class();
- }
- }
-
- // If proxy should be used, inject it. Otherwise apply pending
- // operations, if any.
if ($proxied) {
+ // If proxy should be used, inject it. Otherwise apply pending
+ // operations, if any.
self::$cache = new StudipCacheProxy(self::$cache);
} elseif ($GLOBALS['CACHING_ENABLE'] && $apply_proxied_operations) {
// Even if the above condition will try to eliminate most
@@ -126,6 +108,34 @@ class StudipCacheFactory
return self::$cache;
}
+ /**
+ * Loads the system's configured cache.
+ *
+ * @param bool $enforce_configured_cache Define whether the cache should
+ * be loaded regardless of global
+ * activation
+ */
+ public static function loadSystemCache(bool $enforce_configured_cache = false): StudipCache
+ {
+ if (!$GLOBALS['CACHING_ENABLE'] && !$enforce_configured_cache) {
+ return new StudipMemoryCache();
+ }
+
+ try {
+ $class = self::loadCacheClass();
+ $args = self::retrieveConstructorArguments();
+
+ $cache = self::instantiateCache($class, $args);
+ } catch (\Exception $e) {
+ error_log(__METHOD__ . ': ' . $e->getMessage());
+ PageLayout::addBodyElements(MessageBox::error(__METHOD__ . ': ' . $e->getMessage()));
+
+ $class = self::DEFAULT_CACHE_CLASS;
+ $cache = new $class();
+ }
+
+ return $cache;
+ }
/**
* Load configured cache class and return its name.
@@ -143,7 +153,7 @@ class StudipCacheFactory
$version = new DBSchemaVersion();
if ($version->get(1) < 224) {
// db cache is not yet available, use StudipMemoryCache
- return 'StudipMemoryCache';
+ return StudipMemoryCache::class;
}
return self::DEFAULT_CACHE_CLASS;