Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13] Remove base url from global cache prefix #8745

Merged
merged 7 commits into from Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/theming/lib/ThemingDefaults.php
Expand Up @@ -231,7 +231,7 @@ public function getAndroidClientUrl() {
* @return array scss variables to overwrite
*/
public function getScssVariables() {
$cache = $this->cacheFactory->createDistributed('theming');
$cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl());
if ($value = $cache->get('getScssVariables')) {
return $value;
}
Expand Down Expand Up @@ -298,7 +298,7 @@ public function replaceImagePath($app, $image) {
* @return bool
*/
public function shouldReplaceIcons() {
$cache = $this->cacheFactory->createDistributed('theming');
$cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl());
if($value = $cache->get('shouldReplaceIcons')) {
return (bool)$value;
}
Expand All @@ -320,7 +320,7 @@ public function shouldReplaceIcons() {
private function increaseCacheBuster() {
$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
$this->cacheFactory->createDistributed('theming')->clear('getScssVariables');
$this->cacheFactory->createDistributed('theming-')->clear('getScssVariables');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/theming/tests/ThemingDefaultsTest.php
Expand Up @@ -79,7 +79,7 @@ public function setUp() {
$this->cacheFactory
->expects($this->any())
->method('createDistributed')
->with('theming')
->with('theming-')
->willReturn($this->cache);
$this->template = new ThemingDefaults(
$this->config,
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Server.php
Expand Up @@ -496,7 +496,7 @@ public function __construct($webRoot, \OC\Config $config) {
$version = implode(',', $v);
$instanceId = \OC_Util::getInstanceId();
$path = \OC::$SERVERROOT;
$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl());
$prefix = md5($instanceId . '-' . $version . '-' . $path);
return new \OC\Memcache\Factory($prefix, $c->getLogger(),
$config->getSystemValue('memcache.local', null),
$config->getSystemValue('memcache.distributed', null),
Expand Down Expand Up @@ -963,7 +963,7 @@ public function __construct($webRoot, \OC\Config $config) {
$c->getConfig(),
$c->getThemingDefaults(),
\OC::$SERVERROOT,
$cacheFactory->createDistributed('SCSS')
$this->getMemCacheFactory()
);
});
$this->registerService(JSCombiner::class, function (Server $c) {
Expand All @@ -972,7 +972,7 @@ public function __construct($webRoot, \OC\Config $config) {
return new JSCombiner(
$c->getAppDataDir('js'),
$c->getURLGenerator(),
$cacheFactory->createDistributed('JS'),
$this->getMemCacheFactory(),
$c->getSystemConfig(),
$c->getLogger()
);
Expand Down
13 changes: 9 additions & 4 deletions lib/private/Template/JSCombiner.php
Expand Up @@ -30,6 +30,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\ICacheFactory;
use OCP\ILogger;
use OCP\IURLGenerator;

Expand All @@ -50,21 +51,25 @@ class JSCombiner {
/** @var ILogger */
protected $logger;

/** @var ICacheFactory */
private $cacheFactory;

/**
* @param IAppData $appData
* @param IURLGenerator $urlGenerator
* @param ICache $depsCache
* @param ICacheFactory $cacheFactory
* @param SystemConfig $config
* @param ILogger $logger
*/
public function __construct(IAppData $appData,
IURLGenerator $urlGenerator,
ICache $depsCache,
ICacheFactory $cacheFactory,
SystemConfig $config,
ILogger $logger) {
$this->appData = $appData;
$this->urlGenerator = $urlGenerator;
$this->depsCache = $depsCache;
$this->cacheFactory = $cacheFactory;
$this->depsCache = $this->cacheFactory->createDistributed('JS-' . md5($this->urlGenerator->getBaseUrl()));
$this->config = $config;
$this->logger = $logger;
}
Expand Down Expand Up @@ -236,7 +241,7 @@ public function getContent($root, $file) {
* @throws NotFoundException
*/
public function resetCache() {
$this->depsCache->clear();
$this->cacheFactory->createDistributed('JS-')->clear();
$appDirectory = $this->appData->getDirectoryListing();
foreach ($appDirectory as $folder) {
foreach ($folder->getDirectoryListing() as $file) {
Expand Down
13 changes: 9 additions & 4 deletions lib/private/Template/SCSSCacher.php
Expand Up @@ -39,6 +39,7 @@
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -66,29 +67,33 @@ class SCSSCacher {
/** @var null|string */
protected $injectedVariables = null;

/** @var ICacheFactory */
private $cacheFactory;

/**
* @param ILogger $logger
* @param Factory $appDataFactory
* @param IURLGenerator $urlGenerator
* @param IConfig $config
* @param \OC_Defaults $defaults
* @param string $serverRoot
* @param ICache $depsCache
* @param ICacheFactory $cacheFactory
*/
public function __construct(ILogger $logger,
Factory $appDataFactory,
IURLGenerator $urlGenerator,
IConfig $config,
\OC_Defaults $defaults,
$serverRoot,
ICache $depsCache) {
ICacheFactory $cacheFactory) {
$this->logger = $logger;
$this->appData = $appDataFactory->get('css');
$this->urlGenerator = $urlGenerator;
$this->config = $config;
$this->defaults = $defaults;
$this->serverRoot = $serverRoot;
$this->depsCache = $depsCache;
$this->cacheFactory = $cacheFactory;
$this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl()));
}

/**
Expand Down Expand Up @@ -256,7 +261,7 @@ private function cache($path, $fileNameCSS, $fileNameSCSS, ISimpleFolder $folder
*/
public function resetCache() {
$this->injectedVariables = null;
$this->depsCache->clear();
$this->cacheFactory->createDistributed('SCSS-')->clear();
$appDirectory = $this->appData->getDirectoryListing();
foreach ($appDirectory as $folder) {
foreach ($folder->getDirectoryListing() as $file) {
Expand Down
8 changes: 1 addition & 7 deletions lib/private/TemplateLayout.php
Expand Up @@ -301,13 +301,7 @@ static public function findJavascriptFiles($scripts) {
$theme,
array( \OC::$SERVERROOT => \OC::$WEBROOT ),
array( \OC::$SERVERROOT => \OC::$WEBROOT ),
new JSCombiner(
\OC::$server->getAppDataDir('js'),
\OC::$server->getURLGenerator(),
\OC::$server->getMemCacheFactory()->createDistributed('JS'),
\OC::$server->getSystemConfig(),
\OC::$server->getLogger()
)
\OC::$server->query(JSCombiner::class)
);
$locator->find($scripts);
return $locator->getResources();
Expand Down
11 changes: 6 additions & 5 deletions tests/lib/Template/CSSResourceLocatorTest.php
Expand Up @@ -24,11 +24,12 @@
namespace Test\Template;

use OC\Files\AppData\Factory;
use OCP\Files\IAppData;
use OCP\ICacheFactory;
use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IConfig;
use OCA\Theming\ThemingDefaults;
use OCP\ICache;
use OC\Template\SCSSCacher;
use OC\Template\CSSResourceLocator;

Expand All @@ -41,8 +42,8 @@ class CSSResourceLocatorTest extends \Test\TestCase {
protected $config;
/** @var ThemingDefaults|\PHPUnit_Framework_MockObject_MockObject */
protected $themingDefaults;
/** @var ICache|\PHPUnit_Framework_MockObject_MockObject */
protected $depsCache;
/** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $cacheFactory;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
protected $logger;

Expand All @@ -53,7 +54,7 @@ protected function setUp() {
$this->appData = $this->createMock(IAppData::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->config = $this->createMock(IConfig::class);
$this->depsCache = $this->createMock(ICache::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
}

Expand All @@ -68,7 +69,7 @@ private function cssResourceLocator() {
$this->config,
$this->themingDefaults,
\OC::$SERVERROOT,
$this->depsCache
$this->cacheFactory
);
return new CSSResourceLocator(
$this->logger,
Expand Down
16 changes: 14 additions & 2 deletions tests/lib/Template/JSCombinerTest.php
Expand Up @@ -31,6 +31,7 @@
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\ILogger;
use OCP\IURLGenerator;

Expand All @@ -47,22 +48,29 @@ class JSCombinerTest extends \Test\TestCase {
protected $jsCombiner;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
protected $logger;
/** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $cacheFactory;

protected function setUp() {
parent::setUp();

$this->appData = $this->createMock(IAppData::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->config = $this->createMock(SystemConfig::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->depsCache = $this->createMock(ICache::class);
$this->cacheFactory->expects($this->at(0))
->method('createDistributed')
->willReturn($this->depsCache);
$this->logger = $this->createMock(ILogger::class);
$this->jsCombiner = new JSCombiner(
$this->appData,
$this->urlGenerator,
$this->depsCache,
$this->cacheFactory,
$this->config,
$this->logger
);

}

public function testProcessDebugMode() {
Expand Down Expand Up @@ -522,7 +530,11 @@ public function testResetCache() {
->method('getDirectoryListing')
->willReturn([$file]);

$this->depsCache->expects($this->once())
$cache = $this->createMock(ICache::class);
$this->cacheFactory->expects($this->once())
->method('createDistributed')
->willReturn($cache);
$cache->expects($this->once())
->method('clear')
->with('');
$this->appData->expects($this->once())
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/Template/JSResourceLocatorTest.php
Expand Up @@ -25,8 +25,8 @@

use OC\Template\JSCombiner;
use OCP\Files\IAppData;
use OCP\ICacheFactory;
use OCP\IURLGenerator;
use OCP\ICache;
use OC\SystemConfig;
use OCP\ILogger;
use OC\Template\JSResourceLocator;
Expand All @@ -38,8 +38,8 @@ class JSResourceLocatorTest extends \Test\TestCase {
protected $urlGenerator;
/** @var SystemConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
/** @var ICache|\PHPUnit_Framework_MockObject_MockObject */
protected $depsCache;
/** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $cacheFactory;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
protected $logger;

Expand All @@ -49,15 +49,15 @@ protected function setUp() {
$this->appData = $this->createMock(IAppData::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->config = $this->createMock(SystemConfig::class);
$this->depsCache = $this->createMock(ICache::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->logger = $this->createMock(ILogger::class);
}

private function jsResourceLocator() {
$jsCombiner = new JSCombiner(
$this->appData,
$this->urlGenerator,
$this->depsCache,
$this->cacheFactory,
$this->config,
$this->logger
);
Expand Down
9 changes: 8 additions & 1 deletion tests/lib/Template/SCSSCacherTest.php
Expand Up @@ -31,6 +31,7 @@
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IURLGenerator;
Expand All @@ -50,6 +51,8 @@ class SCSSCacherTest extends \Test\TestCase {
protected $scssCacher;
/** @var ICache|\PHPUnit_Framework_MockObject_MockObject */
protected $depsCache;
/** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $cacheFactory;

protected function setUp() {
parent::setUp();
Expand All @@ -60,7 +63,11 @@ protected function setUp() {
$factory->method('get')->with('css')->willReturn($this->appData);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->config = $this->createMock(IConfig::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->depsCache = $this->createMock(ICache::class);
$this->cacheFactory
->method('createDistributed')
->willReturn($this->depsCache);
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
$this->scssCacher = new SCSSCacher(
$this->logger,
Expand All @@ -69,7 +76,7 @@ protected function setUp() {
$this->config,
$this->themingDefaults,
\OC::$SERVERROOT,
$this->depsCache
$this->cacheFactory
);
$this->themingDefaults->expects($this->any())->method('getScssVariables')->willReturn([]);

Expand Down