From 3801c3aa3f23e5793a12eb8ae62355036d69b917 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20H=C3=A4rtl?= Date: Thu, 15 Jun 2017 12:35:16 +0200 Subject: [PATCH] Make cache and scss caching depend on the baseUrl MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Server.php | 14 ++++++++------ lib/private/Template/SCSSCacher.php | 8 ++++++-- lib/private/URLGenerator.php | 20 +++++++++++++------- lib/public/IURLGenerator.php | 6 ++++++ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/lib/private/Server.php b/lib/private/Server.php index 75e9d911632..081bee3d2ba 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -433,7 +433,13 @@ class Server extends ServerContainer implements IServerContainer { $this->registerAlias('UserCache', \OCP\ICache::class); $this->registerService(Factory::class, function (Server $c) { + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), + '\\OC\\Memcache\\ArrayCache', + '\\OC\\Memcache\\ArrayCache', + '\\OC\\Memcache\\ArrayCache' + ); $config = $c->getConfig(); + $urlGenerator = new URLGenerator($config, $arrayCacheFactory); if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { $v = \OC_App::getAppVersions(); @@ -441,19 +447,15 @@ class Server extends ServerContainer implements IServerContainer { $version = implode(',', $v); $instanceId = \OC_Util::getInstanceId(); $path = \OC::$SERVERROOT; - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); return new \OC\Memcache\Factory($prefix, $c->getLogger(), $config->getSystemValue('memcache.local', null), $config->getSystemValue('memcache.distributed', null), $config->getSystemValue('memcache.locking', null) ); } + return $arrayCacheFactory; - return new \OC\Memcache\Factory('', $c->getLogger(), - '\\OC\\Memcache\\ArrayCache', - '\\OC\\Memcache\\ArrayCache', - '\\OC\\Memcache\\ArrayCache' - ); }); $this->registerAlias('MemCacheFactory', Factory::class); $this->registerAlias(ICacheFactory::class, Factory::class); diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 6b1c594bd2e..eccc65a5cc9 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -92,7 +92,7 @@ class SCSSCacher { $path = explode('/', $root . '/' . $file); $fileNameSCSS = array_pop($path); - $fileNameCSS = str_replace('.scss', '.css', $fileNameSCSS); + $fileNameCSS = $this->getBaseUrlHash() . '-' . str_replace('.scss', '.css', $fileNameSCSS); $path = implode('/', $path); @@ -292,8 +292,12 @@ class SCSSCacher { public function getCachedSCSS($appName, $fileName) { $tmpfileLoc = explode('/', $fileName); $fileName = array_pop($tmpfileLoc); - $fileName = str_replace('.scss', '.css', $fileName); + $fileName = $this->getBaseUrlHash() . '-' . str_replace('.scss', '.css', $fileName); return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $fileName, 'appName' => $appName)), strlen(\OC::$WEBROOT) + 1); } + + private function getBaseUrlHash() { + return md5($this->urlGenerator->getBaseUrl()); + } } diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index 2387deb6100..6db675e7d77 100644 --- a/lib/private/URLGenerator.php +++ b/lib/private/URLGenerator.php @@ -142,7 +142,7 @@ class URLGenerator implements IURLGenerator { * Returns the path to the image. */ public function imagePath($app, $image) { - $cache = $this->cacheFactory->create('imagePath'); + $cache = $this->cacheFactory->create('imagePath-'.md5($this->getBaseUrl()).'-'); $cacheKey = $app.'-'.$image; if($key = $cache->get($cacheKey)) { return $key; @@ -223,14 +223,12 @@ class URLGenerator implements IURLGenerator { if (\OC::$CLI && !defined('PHPUNIT_RUN')) { return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/'); } - // The ownCloud web root can already be prepended. - $webRoot = substr($url, 0, strlen(\OC::$WEBROOT)) === \OC::$WEBROOT - ? '' - : \OC::$WEBROOT; + if(substr($url, 0, strlen(\OC::$WEBROOT)) === \OC::$WEBROOT) { + $url = substr($url, strlen(\OC::$WEBROOT)); + } - $request = \OC::$server->getRequest(); - return $request->getServerProtocol() . '://' . $request->getServerHost() . $webRoot . $separator . $url; + return $this->getBaseUrl() . $separator . $url; } /** @@ -241,4 +239,12 @@ class URLGenerator implements IURLGenerator { $theme = \OC::$server->getThemingDefaults(); return $theme->buildDocLinkToKey($key); } + + /** + * @return string base url of the current request + */ + public function getBaseUrl() { + $request = \OC::$server->getRequest(); + return $request->getServerProtocol() . '://' . $request->getServerHost() . \OC::$WEBROOT; + } } diff --git a/lib/public/IURLGenerator.php b/lib/public/IURLGenerator.php index e309336c0f0..3869d2f86f8 100644 --- a/lib/public/IURLGenerator.php +++ b/lib/public/IURLGenerator.php @@ -91,4 +91,10 @@ interface IURLGenerator { * @since 8.0.0 */ public function linkToDocs($key); + + /** + * @return string base url of the current request + * @since 13.0.0 + */ + public function getBaseUrl(); } -- 2.39.5