aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/cache/Factory.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/classes/cache/Factory.php')
-rw-r--r--lib/classes/cache/Factory.php60
1 files changed, 35 insertions, 25 deletions
diff --git a/lib/classes/cache/Factory.php b/lib/classes/cache/Factory.php
index b5c8359..0def769 100644
--- a/lib/classes/cache/Factory.php
+++ b/lib/classes/cache/Factory.php
@@ -92,33 +92,15 @@ class Factory
public static function getCache(bool $apply_proxied_operations = true): Cache
{
if (self::$cache === null) {
- $proxied = false;
+ $proxied = !$GLOBALS['CACHING_ENABLE']
+ && isset($GLOBALS['GLOBAL_CACHING_ENABLE'])
+ && $GLOBALS['GLOBAL_CACHING_ENABLE'];
- if (!$GLOBALS['CACHING_ENABLE']) {
- self::$cache = new MemoryCache();
+ 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 Proxy(self::$cache);
} elseif ($GLOBALS['CACHING_ENABLE'] && $apply_proxied_operations) {
// Even if the above condition will try to eliminate most
@@ -136,6 +118,34 @@ class Factory
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): Cache
+ {
+ if (!$GLOBALS['CACHING_ENABLE'] && !$enforce_configured_cache) {
+ return new MemoryCache();
+ }
+
+ 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.
@@ -153,7 +163,7 @@ class Factory
$version = new DBSchemaVersion();
if ($version->get(1) < 224) {
// db cache is not yet available, use StudipMemoryCache
- return 'StudipMemoryCache';
+ return MemoryCache::class;
}
return self::DEFAULT_CACHE_CLASS;