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

Update CacheClearer adapter #10770

Merged
merged 12 commits into from
Oct 17, 2018
83 changes: 73 additions & 10 deletions src/Adapter/Cache/CacheClearer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,110 @@

namespace PrestaShop\PrestaShop\Adapter\Cache;

use Tools;
use Media;
use PrestaShop\PrestaShop\Core\Cache\Clearer\CacheClearerInterface;

/**
* Class able to clear application caches.
*
* @internal
*/
class CacheClearer
{
/**
* @var CacheClearerInterface
*/
private $cacheClearerChain;

/**
* @var CacheClearerInterface
*/
private $symfonyCacheClearer;

/**
* @var CacheClearerInterface
*/
private $mediaCacheClearer;

/**
* @var CacheClearerInterface
*/
private $smartyCacheClearer;

/**
* @param CacheClearerInterface $cacheClearerChain
* @param CacheClearerInterface $symfonyCacheClearer
* @param CacheClearerInterface $mediaCacheClearer
* @param CacheClearerInterface $smartyCacheClearer
*/
public function __construct(
Copy link
Contributor

Choose a reason for hiding this comment

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

Watch out, with this you introduce a BC break because of the necessary of having parameters.

Copy link
Contributor Author

@sarjon sarjon Sep 29, 2018

Choose a reason for hiding this comment

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

i know, but do Adapters promise BC? i think that modules should not depend on adapters, but if they do, then they should not expect BC as adapters are temporary services that can change/be removed at any time, no? 🤔

Copy link
Contributor

@PierreRambaud PierreRambaud Sep 29, 2018

Choose a reason for hiding this comment

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

There is always a difference between what we think and what users do :D Maybe we can for the moment use a function like addCacheClearer and call this class CacheClearerChain?

Copy link
Contributor

Choose a reason for hiding this comment

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

With this, we sure we don't have BC or anything else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i could just leave this CacheClearer untouched, because if it is used in some module (even though it shouldnt :D) it will break as you must call addCacheClearer to make it work, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about the backward compatibility for Adapter services as well, but anyway I think an addCacheClearer method here wouldn't hurt anyway if you need to add an extra cache clearer layer
If some module is using the service via the container (->get('service_name')) it won't make a difference anyway, if it instanciated it manually, there's nothing we can do anyway.. too bad for them

Copy link
Contributor Author

@sarjon sarjon Oct 15, 2018

Choose a reason for hiding this comment

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

@matks wdyt? i dont really want do add non interfaced method to a service. we could either dispatch event though which you could add more cache clearers or just use composition.

CacheClearerInterface $cacheClearerChain,
CacheClearerInterface $symfonyCacheClearer,
CacheClearerInterface $mediaCacheClearer,
CacheClearerInterface $smartyCacheClearer
) {
$this->cacheClearerChain = $cacheClearerChain;
$this->symfonyCacheClearer = $symfonyCacheClearer;
$this->mediaCacheClearer = $mediaCacheClearer;
$this->smartyCacheClearer = $smartyCacheClearer;
}

/**
* Clear all application caches.
*
* @deprecated since 1.7.6. Use CacheClearerChain instead.
*/
public function clearAllCaches()
{
$this->clearSymfonyCache();
$this->clearSmartyCache();
Tools::clearXMLCache();
$this->clearMediaCache();
Tools::generateIndex();
trigger_error(
'Deprecated since 1.7.6, to be removed in 1.8. Use CacheClearerChain instead.',
E_USER_DEPRECATED
);

$this->cacheClearerChain->clear();
}

/**
* Clear Symfony cache.
*
* @deprecated since 1.7.6. Use SymfonyCacheClearer instead.
*/
public function clearSymfonyCache()
{
Tools::clearSf2Cache();
trigger_error(
'Deprecated since 1.7.6, to be removed in 1.8. Use SymfonyCacheClearer instead.',
E_USER_DEPRECATED
);

$this->symfonyCacheClearer->clear();
}

/**
* Clear media cache only.
*
* @deprecated since 1.7.6. Use MediaCacheClearer instead.
*/
public function clearMediaCache()
{
Media::clearCache();
trigger_error(
'Deprecated since 1.7.6, to be removed in 1.8. Use MediaCacheClearer instead.',
E_USER_DEPRECATED
);

$this->mediaCacheClearer->clear();
}

/**
* Clear smarty cache only.
*
* @deprecated since 1.7.6. Use SmartyCacheClearer instead.
*/
public function clearSmartyCache()
{
Tools::clearSmartyCache();
trigger_error(
'Deprecated since 1.7.6, to be removed in 1.8. Use SmartyCacheClearer instead.',
E_USER_DEPRECATED
);

$this->smartyCacheClearer->clear();
}
}
18 changes: 13 additions & 5 deletions src/Adapter/Cache/CachingConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace PrestaShop\PrestaShop\Adapter\Cache;

use PrestaShop\PrestaShop\Adapter\Configuration\PhpParameters;
use PrestaShop\PrestaShop\Core\Cache\Clearer\CacheClearerInterface;
use PrestaShop\PrestaShop\Core\Configuration\DataConfigurationInterface;

/**
Expand All @@ -45,9 +46,9 @@ class CachingConfiguration implements DataConfigurationInterface
private $phpParameters;

/**
* @var CacheClearer
* @var CacheClearerInterface
*/
private $cacheClearer;
private $symfonyCacheClearer;

/**
* @var bool check if the caching is enabled
Expand All @@ -59,16 +60,23 @@ class CachingConfiguration implements DataConfigurationInterface
*/
private $cachingSystem;

/**
* @param MemcacheServerManager $memcacheServerManager
* @param PhpParameters $phpParameters
* @param CacheClearerInterface $symfonyCacheClearer
* @param $isCachingEnabled
* @param $cachingSystem
*/
public function __construct(
MemcacheServerManager $memcacheServerManager,
PhpParameters $phpParameters,
CacheClearer $cacheClearer,
CacheClearerInterface $symfonyCacheClearer,
$isCachingEnabled,
$cachingSystem
) {
$this->memcacheServerManager = $memcacheServerManager;
$this->phpParameters = $phpParameters;
$this->cacheClearer = $cacheClearer;
$this->symfonyCacheClearer = $symfonyCacheClearer;
$this->isCachingEnabled = $isCachingEnabled;
$this->cachingSystem = $cachingSystem;
}
Expand Down Expand Up @@ -142,7 +150,7 @@ private function updatePhpCacheConfiguration(array $configuration)
);
}

$this->cacheClearer->clearSymfonyCache();
$this->symfonyCacheClearer->clear();

return $errors;
}
Expand Down
46 changes: 46 additions & 0 deletions src/Adapter/Cache/Clearer/ClassIndexCacheClearer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

namespace PrestaShop\PrestaShop\Adapter\Cache\Clearer;

use PrestaShop\PrestaShop\Core\Cache\Clearer\CacheClearerInterface;
use PrestaShopAutoload;

/**
* Class ClassIndexCacheClearer clears current class index and generates new one.
*
* @internal
*/
final class ClassIndexCacheClearer implements CacheClearerInterface
{
/**
* {@inheritdoc}
*/
public function clear()
{
PrestaShopAutoload::getInstance()->generateIndex();
}
}
46 changes: 46 additions & 0 deletions src/Adapter/Cache/Clearer/MediaCacheClearer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

namespace PrestaShop\PrestaShop\Adapter\Cache\Clearer;

use Media;
use PrestaShop\PrestaShop\Core\Cache\Clearer\CacheClearerInterface;

/**
* Class MediaCacheClearer clears Front Office theme's Javascript & CSS cache.
*
* @internal
*/
final class MediaCacheClearer implements CacheClearerInterface
{
/**
* {@inheritdoc}
*/
public function clear()
{
Media::clearCache();
}
}
46 changes: 46 additions & 0 deletions src/Adapter/Cache/Clearer/SmartyCacheClearer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

namespace PrestaShop\PrestaShop\Adapter\Cache\Clearer;

use PrestaShop\PrestaShop\Core\Cache\Clearer\CacheClearerInterface;
use Tools;

/**
* Class SmartyCacheClearer clears Smarty cache.
*
* @internal
*/
final class SmartyCacheClearer implements CacheClearerInterface
{
/**
* {@inheritdoc}
*/
public function clear()
{
Tools::clearSmartyCache();
}
}
46 changes: 46 additions & 0 deletions src/Adapter/Cache/Clearer/SymfonyCacheClearer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

namespace PrestaShop\PrestaShop\Adapter\Cache\Clearer;

use PrestaShop\PrestaShop\Core\Cache\Clearer\CacheClearerInterface;
use Tools;

/**
* Class SymfonyCacheClearer clears Symfony cache directly from filesystem.
*
* @internal
*/
final class SymfonyCacheClearer implements CacheClearerInterface
{
/**
* {@inheritdoc}
*/
public function clear()
{
Tools::clearSf2Cache();
}
}
Loading