Skip to content
Snippets Groups Projects
Commit 79479dd3 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

allow cache settings to be configured even if caching is disabled, fixes #4806

Closes #4806

Merge request studip/studip!3597
parent 807bc592
No related branches found
No related tags found
No related merge requests found
......@@ -47,16 +47,14 @@ class Admin_CacheController extends AuthenticatedController
$this->sidebar->addWidget($views);
if ($this->enabled) {
$actions = new ActionsWidget();
$actions->addLink(
_('Cache leeren'),
$this->url_for('admin/cache/flush'),
Icon::create('decline'),
['data-confirm' => _('Soll der gesamte Inhalt des Caches wirklich gelöscht werden?')]
);
$this->sidebar->addWidget($actions);
}
$actions = new ActionsWidget();
$actions->addLink(
_('Cache leeren'),
$this->url_for('admin/cache/flush'),
Icon::create('decline'),
['data-confirm' => _('Soll der gesamte Inhalt des Caches wirklich gelöscht werden?')]
);
$this->sidebar->addWidget($actions);
}
/**
......@@ -123,7 +121,7 @@ class Admin_CacheController extends AuthenticatedController
*/
public function flush_action()
{
$cache = \Studip\Cache\Factory::getCache();
$cache = \Studip\Cache\Factory::loadSystemCache(true);
$cache->flush();
PageLayout::postSuccess(_('Die Inhalte des Caches wurden gelöscht.'));
......
......@@ -5,6 +5,7 @@ StudipAutoloader::register();
class_alias(\Studip\Cache\Factory::class, 'StudipCacheFactory');
class_alias(\Studip\Cache\Cache::class, 'StudipCache');
class_alias(\Studip\Cache\DbCache::class, 'StudipDbCache');
class_alias(Flexi\PhpTemplate::class, 'Flexi_PhpTemplate');
class_alias(Flexi\Template::class, 'Flexi_Template');
class_alias(Flexi\Factory::class, 'Flexi_TemplateFactory');
......
......@@ -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;
......
<template>
<StudipMessageBox v-if="!enabled" type="warning" :hide-close="true">
{{ $gettext('Caching ist systemweit ausgeschaltet, daher kann hier nichts konfiguriert werden.') }}
</StudipMessageBox>
<form v-else class="default" :action="actionUrl" method="post" ref="configForm">
<form class="default" :action="actionUrl" method="post" ref="configForm">
<StudipMessageBox v-if="!enabled" type="warning" :hide-close="true">
{{ $gettext('Caching ist systemweit ausgeschaltet.') }}
</StudipMessageBox>
<fieldset>
<legend>
<translate>Cachetyp</translate>
......
......@@ -38,6 +38,7 @@ foreach($added_configs as $key => $value) {
$GLOBALS[$key] = $value;
}
require 'config/config.inc.php';
require_once __DIR__ . '/../../lib/bootstrap-autoload.php';
// Do not send mails of any kind during tests
require 'vendor/email_message/email_message.php';
......
......@@ -28,6 +28,8 @@ $CACHING_ENABLE = false;
date_default_timezone_set('Europe/Berlin');
require 'config.inc.php';
require_once __DIR__ . '/../../lib/bootstrap-autoload.php';
require 'lib/helpers.php';
require 'lib/functions.php';
......@@ -58,6 +60,6 @@ class DB_Seminar extends DB_Sql
}
}
require_once __DIR__.'/../../composer/autoload.php';
require_once __DIR__ . '/../../composer/autoload.php';
session_id("test-session");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment