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

BUGFIX: Make cache application identifier configurable #1457

Merged
merged 5 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Neos.Flow/Classes/Cache/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@ public function injectEnvironmentConfiguration(EnvironmentConfiguration $environ
*
* @param ApplicationContext $context The current Flow context
* @param Environment $environment
* @param string $applicationIdentifier
* @Flow\Autowiring(enabled=false)
*/
public function __construct(ApplicationContext $context, Environment $environment)
public function __construct(ApplicationContext $context, Environment $environment, string $applicationIdentifier)
{
$this->context = $context;
$this->environment = $environment;

$environmentConfiguration = new EnvironmentConfiguration(
FLOW_PATH_ROOT . '~' . (string)$environment->getContext(),
$applicationIdentifier,
$environment->getPathToTemporaryDirectory()
);

Expand Down
2 changes: 1 addition & 1 deletion Neos.Flow/Classes/Core/Booting/Scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static function initializeCacheManagement(Bootstrap $bootstrap)
$cacheFactoryClass = isset($cacheFactoryObjectConfiguration['className']) ? $cacheFactoryObjectConfiguration['className'] : CacheFactory::class;

/** @var CacheFactory $cacheFactory */
$cacheFactory = new $cacheFactoryClass($bootstrap->getContext(), $environment);
$cacheFactory = new $cacheFactoryClass($bootstrap->getContext(), $environment, $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow.cache.applicationIdentifier'));

$cacheManager = new CacheManager();
$cacheManager->setCacheConfigurations($configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_CACHES));
Expand Down
3 changes: 2 additions & 1 deletion Neos.Flow/Classes/Core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,9 @@ protected function defineConstants()
}

define('FLOW_ONLY_COMPOSER_LOADER', $onlyUseComposerAutoLoaderForPackageClasses);

define('FLOW_VERSION_BRANCH', '4.3');

define('FLOW_APPLICATION_CONTEXT', (string)$this->context);
}

/**
Expand Down
14 changes: 9 additions & 5 deletions Neos.Flow/Configuration/Objects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ Composer\Autoload\ClassLoader:
Neos\Cache\CacheFactoryInterface:
className: Neos\Flow\Cache\CacheFactory

Neos\Flow\Cache\CacheFactory:
arguments:
1:
setting: Neos.Flow.context

Neos\Flow\Cache\CacheManager:
properties:
logger:
object:
factoryObjectName: Neos\Flow\Log\PsrLoggerFactoryInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No such thing as Neos\Flow\Log\PsrLoggerFactoryInterface in Flow 4.3

factoryMethodName: get
arguments:
1:
value: systemLogger

# #
# I18n #
Expand Down
12 changes: 12 additions & 0 deletions Neos.Flow/Configuration/Settings.Cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Neos:
Flow:
cache:
# The application identifier can be used by cache backends to differentiate cache entries
# with the same cache identifier in the same storage from each other. For example memcache is global,
# so if you use it for multiple installations or possibly just for different Flow contexts you need to
# find a way to separate entries from each other. This setting will do that.
# The default is just for backwards compatibility and might change for the next major. It is not well suited
# for installations in which the FLOW_PATH_ROOT changes after each deployment, so in such cases you might
# want to exchange it for some hardcoded value identifying this specific installation.
# Note that changing it will make cache entries generated with the old identifier useless.
applicationIdentifier: '%FLOW_PATH_ROOT%~%FLOW_APPLICATION_CONTEXT%'
6 changes: 3 additions & 3 deletions Neos.Flow/Tests/Unit/Cache/CacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function setUp()
*/
public function createReturnsInstanceOfTheSpecifiedCacheFrontend()
{
$factory = new CacheFactory(new ApplicationContext('Testing'), $this->mockEnvironment);
$factory = new CacheFactory(new ApplicationContext('Testing'), $this->mockEnvironment, 'UnitTesting');
$factory->injectEnvironmentConfiguration($this->mockEnvironmentConfiguration);

$cache = $factory->create('TYPO3_Flow_Cache_FactoryTest_Cache', VariableFrontend::class, NullBackend::class);
Expand All @@ -87,7 +87,7 @@ public function createReturnsInstanceOfTheSpecifiedCacheFrontend()
*/
public function createInjectsAnInstanceOfTheSpecifiedBackendIntoTheCacheFrontend()
{
$factory = new CacheFactory(new ApplicationContext('Testing'), $this->mockEnvironment);
$factory = new CacheFactory(new ApplicationContext('Testing'), $this->mockEnvironment, 'UnitTesting');
$factory->injectEnvironmentConfiguration($this->mockEnvironmentConfiguration);

$cache = $factory->create('TYPO3_Flow_Cache_FactoryTest_Cache', VariableFrontend::class, FileBackend::class);
Expand All @@ -100,7 +100,7 @@ public function createInjectsAnInstanceOfTheSpecifiedBackendIntoTheCacheFrontend
public function aDifferentDefaultCacheDirectoryIsUsedForPersistentFileCaches()
{
$cacheManager = new CacheManager();
$factory = new CacheFactory(new ApplicationContext('Testing'), $this->mockEnvironment);
$factory = new CacheFactory(new ApplicationContext('Testing'), $this->mockEnvironment, 'UnitTesting');
$factory->injectCacheManager($cacheManager);
$factory->injectEnvironmentConfiguration($this->mockEnvironmentConfiguration);

Expand Down