Skip to content

Commit

Permalink
Merge pull request ezsystems#1134 from ezsystems/EZP-23867-legacy_bri…
Browse files Browse the repository at this point in the history
…dge_signal_slots

Separate legacy and new stack cache handling
  • Loading branch information
bdunogier committed Jan 16, 2015
2 parents cc689d4 + 29f7f89 commit 3484808
Show file tree
Hide file tree
Showing 40 changed files with 324 additions and 154 deletions.
47 changes: 10 additions & 37 deletions eZ/Bundle/EzPublishLegacyBundle/Cache/PersistenceCachePurger.php
Expand Up @@ -21,6 +21,8 @@
*/
class PersistenceCachePurger implements CacheClearerInterface
{
use Switchable;

/**
* @var \eZ\Publish\Core\Persistence\Cache\CacheServiceDecorator
*/
Expand All @@ -38,13 +40,6 @@ class PersistenceCachePurger implements CacheClearerInterface
*/
protected $allCleared = false;

/**
* Activation flag.
*
* @var bool
*/
protected $enabled = true;

/**
* @var \Psr\Log\LoggerInterface
*/
Expand All @@ -71,7 +66,7 @@ public function __construct( CacheServiceDecorator $cache, LocationHandlerInterf
*/
public function all()
{
if ( $this->enabled === false )
if ( $this->isSwitchedOff() )
return;

$this->cache->clear();
Expand Down Expand Up @@ -100,28 +95,6 @@ public function resetAllCleared()
$this->allCleared = false;
}

/**
* Enables or disables cache purger.
* Disabling the cache purger might be useful in certain situations
* (like setup wizard where legacy cache is cleared but everything is not set yet to correctly clear SPI cache).
*
* @param bool $isEnabled
*/
public function setEnabled( $isEnabled )
{
$this->enabled = (bool)$isEnabled;
}

/**
* Checks if cache purger is enabled or not.
*
* @return bool
*/
public function isEnabled()
{
return $this->enabled;
}

/**
* Clear all content persistence cache, or by locationIds (legacy content/cache mechanism is location based).
*
Expand All @@ -135,8 +108,8 @@ public function isEnabled()
*/
public function content( $locationIds = null )
{
if ( $this->allCleared === true || $this->enabled === false )
return;
if ( $this->allCleared === true || $this->isSwitchedOff() )
return $locationIds;

if ( $locationIds === null )
{
Expand Down Expand Up @@ -187,7 +160,7 @@ public function content( $locationIds = null )
*/
public function contentType( $id = null )
{
if ( $this->allCleared === true || $this->enabled === false )
if ( $this->allCleared === true || $this->isSwitchedOff() )
return;

if ( $id === null )
Expand All @@ -214,7 +187,7 @@ public function contentType( $id = null )
*/
public function contentTypeGroup( $id = null )
{
if ( $this->allCleared === true || $this->enabled === false )
if ( $this->allCleared === true || $this->isSwitchedOff() )
return;

if ( $id === null )
Expand Down Expand Up @@ -242,7 +215,7 @@ public function contentTypeGroup( $id = null )
*/
public function section( $id = null )
{
if ( $this->allCleared === true || $this->enabled === false )
if ( $this->allCleared === true || $this->isSwitchedOff() )
return;

if ( $id === null )
Expand All @@ -266,7 +239,7 @@ public function section( $id = null )
*/
public function languages( $ids )
{
if ( $this->allCleared === true || $this->enabled === false )
if ( $this->allCleared === true || $this->isSwitchedOff() )
return;

$ids = (array)$ids;
Expand All @@ -282,7 +255,7 @@ public function languages( $ids )
*/
public function user( $id = null )
{
if ( $this->allCleared === true || $this->enabled === false )
if ( $this->allCleared === true || $this->isSwitchedOff() )
return;

if ( $id === null )
Expand Down
42 changes: 42 additions & 0 deletions eZ/Bundle/EzPublishLegacyBundle/Cache/Switchable.php
@@ -0,0 +1,42 @@
<?php
/**
* This file is part of the eZ Publish Kernel package
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Bundle\EzPublishLegacyBundle\Cache;

trait Switchable
{
/** @var bool */
private $isSwitchedOn = true;

public function switchOn()
{
$this->isSwitchedOn = true;
}

public function switchOff()
{
$this->isSwitchedOn = false;
}

/**
* Checks if the switch is off
* @return bool
*/
public function isSwitchedOn()
{
return $this->isSwitchedOn;
}

/**
* Checks if the switch is off
* @return bool
*/
public function isSwitchedOff()
{
return !$this->isSwitchedOn;
}
}
@@ -0,0 +1,46 @@
<?php
/**
* This file is part of the EzPublishLegacyBridge package
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Bundle\EzPublishLegacyBundle\Cache;

use eZ\Publish\Core\MVC\Symfony\Cache\GatewayCachePurger;

/**
* A GatewayCachePurger decorator that allows the actual purger to be switched on/off.
*/
class SwitchableHttpCachePurger implements GatewayCachePurger
{
use Switchable;

/** @var \eZ\Publish\Core\MVC\Symfony\Cache\GatewayCachePurger */
private $gatewayCachePurger;

public function __construct( GatewayCachePurger $gatewayCachePurger )
{
$this->gatewayCachePurger = $gatewayCachePurger;
}

public function purge( $cacheElements )
{
if ( $this->isSwitchedOff() )
{
return $cacheElements;
}

return $this->gatewayCachePurger->purge( $cacheElements );
}

public function purgeAll()
{
if ( $this->isSwitchedOff() )
{
return;
}

$this->gatewayCachePurger->purgeAll();
}
}
Expand Up @@ -80,7 +80,7 @@ public function init()
{
// Ensure that persistence cache purger is disabled as legacy cache will be cleared by legacy setup wizard while
// everything is not ready yet to clear SPI cache (no connection to repository yet).
$this->persistenceCachePurger->setEnabled( false );
$this->persistenceCachePurger->switchOff();

// we disable injection of settings to Legacy Kernel during setup
$this->kernelFactory->setBuildEventsEnabled( false );
Expand Down
Expand Up @@ -57,6 +57,7 @@ parameters:
# Cache purging
ezpublish_legacy.persistence_cache_purger.class: eZ\Bundle\EzPublishLegacyBundle\Cache\PersistenceCachePurger
ezpublish_legacy.legacy_cache_purger.class: eZ\Bundle\EzPublishLegacyBundle\Cache\LegacyCachePurger
ezpublish_legacy.switchable_http_cache_purger.class: eZ\Bundle\EzPublishLegacyBundle\Cache\SwitchableHttpCachePurger

# Overriding base PageService for ezpage fieldtype.
ezpublish.fieldType.ezpage.pageService.class: eZ\Bundle\EzPublishLegacyBundle\FieldType\Page\PageService
Expand Down Expand Up @@ -198,7 +199,7 @@ services:
class: %ezpublish_legacy.configuration_mapper.class%
arguments:
- @ezpublish.config.resolver.core
- @ezpublish.http_cache.purger
- @ezpublish_legacy.switchable_http_cache_purger
- @ezpublish_legacy.persistence_cache_purger
- @ezpublish.urlalias_generator
- @ezpublish.api.storage_engine.legacy.dbhandler
Expand Down Expand Up @@ -235,6 +236,10 @@ services:
tags:
- { name: kernel.cache_clearer }

ezpublish_legacy.switchable_http_cache_purger:
class: %ezpublish_legacy.switchable_http_cache_purger.class%
arguments: [@ezpublish.http_cache.purger]

ezpublish_legacy.content_exception_handler:
class: %ezpublish_legacy.content_exception_handler.class%
arguments: [@ezpublish_legacy.content_view_provider, @ezpublish_legacy.location_view_provider, @?logger]
Expand Down

0 comments on commit 3484808

Please sign in to comment.