summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2017-06-15 12:35:16 +0200
committerJulius Härtl <jus@bitgrid.net>2017-06-15 12:46:24 +0200
commit0789adaf95d2cfea8d661812b7dd964b0611495b (patch)
tree1837c8826c3b20fa78c5e3a9d4b42202974923b2
parentca3c69c8ae0fd7f0d13e87d7861c54e2950a2c09 (diff)
downloadnextcloud-server-0789adaf95d2cfea8d661812b7dd964b0611495b.tar.gz
nextcloud-server-0789adaf95d2cfea8d661812b7dd964b0611495b.zip
Make cache and scss caching depend on the baseUrl
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r--lib/private/Server.php14
-rw-r--r--lib/private/Template/SCSSCacher.php8
-rw-r--r--lib/private/URLGenerator.php20
-rw-r--r--lib/public/IURLGenerator.php6
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();
}