Make cache and scss caching depend on the baseUrl

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2017-06-15 12:35:16 +02:00
parent f02575db94
commit 3801c3aa3f
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
4 changed files with 33 additions and 15 deletions

View File

@ -433,7 +433,13 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerAlias('UserCache', \OCP\ICache::class); $this->registerAlias('UserCache', \OCP\ICache::class);
$this->registerService(Factory::class, function (Server $c) { $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(); $config = $c->getConfig();
$urlGenerator = new URLGenerator($config, $arrayCacheFactory);
if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
$v = \OC_App::getAppVersions(); $v = \OC_App::getAppVersions();
@ -441,19 +447,15 @@ class Server extends ServerContainer implements IServerContainer {
$version = implode(',', $v); $version = implode(',', $v);
$instanceId = \OC_Util::getInstanceId(); $instanceId = \OC_Util::getInstanceId();
$path = \OC::$SERVERROOT; $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(), return new \OC\Memcache\Factory($prefix, $c->getLogger(),
$config->getSystemValue('memcache.local', null), $config->getSystemValue('memcache.local', null),
$config->getSystemValue('memcache.distributed', null), $config->getSystemValue('memcache.distributed', null),
$config->getSystemValue('memcache.locking', 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('MemCacheFactory', Factory::class);
$this->registerAlias(ICacheFactory::class, Factory::class); $this->registerAlias(ICacheFactory::class, Factory::class);

View File

@ -92,7 +92,7 @@ class SCSSCacher {
$path = explode('/', $root . '/' . $file); $path = explode('/', $root . '/' . $file);
$fileNameSCSS = array_pop($path); $fileNameSCSS = array_pop($path);
$fileNameCSS = str_replace('.scss', '.css', $fileNameSCSS); $fileNameCSS = $this->getBaseUrlHash() . '-' . str_replace('.scss', '.css', $fileNameSCSS);
$path = implode('/', $path); $path = implode('/', $path);
@ -292,8 +292,12 @@ class SCSSCacher {
public function getCachedSCSS($appName, $fileName) { public function getCachedSCSS($appName, $fileName) {
$tmpfileLoc = explode('/', $fileName); $tmpfileLoc = explode('/', $fileName);
$fileName = array_pop($tmpfileLoc); $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); 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());
}
} }

View File

@ -142,7 +142,7 @@ class URLGenerator implements IURLGenerator {
* Returns the path to the image. * Returns the path to the image.
*/ */
public function imagePath($app, $image) { public function imagePath($app, $image) {
$cache = $this->cacheFactory->create('imagePath'); $cache = $this->cacheFactory->create('imagePath-'.md5($this->getBaseUrl()).'-');
$cacheKey = $app.'-'.$image; $cacheKey = $app.'-'.$image;
if($key = $cache->get($cacheKey)) { if($key = $cache->get($cacheKey)) {
return $key; return $key;
@ -223,14 +223,12 @@ class URLGenerator implements IURLGenerator {
if (\OC::$CLI && !defined('PHPUNIT_RUN')) { if (\OC::$CLI && !defined('PHPUNIT_RUN')) {
return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/'); return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/');
} }
// The ownCloud web root can already be prepended. // The ownCloud web root can already be prepended.
$webRoot = substr($url, 0, strlen(\OC::$WEBROOT)) === \OC::$WEBROOT if(substr($url, 0, strlen(\OC::$WEBROOT)) === \OC::$WEBROOT) {
? '' $url = substr($url, strlen(\OC::$WEBROOT));
: \OC::$WEBROOT; }
$request = \OC::$server->getRequest(); return $this->getBaseUrl() . $separator . $url;
return $request->getServerProtocol() . '://' . $request->getServerHost() . $webRoot . $separator . $url;
} }
/** /**
@ -241,4 +239,12 @@ class URLGenerator implements IURLGenerator {
$theme = \OC::$server->getThemingDefaults(); $theme = \OC::$server->getThemingDefaults();
return $theme->buildDocLinkToKey($key); 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;
}
} }

View File

@ -91,4 +91,10 @@ interface IURLGenerator {
* @since 8.0.0 * @since 8.0.0
*/ */
public function linkToDocs($key); public function linkToDocs($key);
/**
* @return string base url of the current request
* @since 13.0.0
*/
public function getBaseUrl();
} }