Skip to content

Commit

Permalink
Merge pull request #769 from PrestaShopCorp/feat/force-clear-module-c…
Browse files Browse the repository at this point in the history
…ache

[MME-489] ✨ Clear module cache once a day
  • Loading branch information
intraordinaire authored Sep 3, 2024
2 parents 03ef6eb + 3e5d4ca commit a00b3f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_mbo</name>
<displayName><![CDATA[PrestaShop Marketplace in your Back Office]]></displayName>
<version><![CDATA[3.1.3]]></version>
<version><![CDATA[3.1.4]]></version>
<description><![CDATA[Discover the best PrestaShop modules to optimize your online store.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
Expand Down
34 changes: 33 additions & 1 deletion ps_mbo.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use PrestaShop\Module\Mbo\Service\View\ContextBuilder;
use PrestaShop\Module\Mbo\Tab\TabCollectionProvider;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder;
use PrestaShop\PsAccountsInstaller\Installer\Installer;
use Ramsey\Uuid\Uuid;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -176,7 +177,7 @@ class ps_mbo extends Module
public function __construct()
{
$this->name = 'ps_mbo';
$this->version = '3.1.3';
$this->version = '3.1.4';
$this->author = 'PrestaShop';
$this->tab = 'administration';
$this->module_key = '6cad5414354fbef755c7df4ef1ab74eb';
Expand Down Expand Up @@ -627,6 +628,37 @@ public function hookActionDispatcherBefore()
$this->ensureShopIsRegistered();
$this->ensureShopIsUpdated();
}

try {
/**
* @var CacheProvider $cacheProvider
*/
$cacheProvider = $this->get('doctrine.cache.provider');
} catch (Exception $e) {
$cacheProvider = null;
}
$cacheKey = 'mbo_cache_modules_list_cleared';

// Force clearing cache on module data at least once a day
if ($cacheProvider && !$cacheProvider->fetch($cacheKey)) {
$moduleManagerBuilder = ModuleManagerBuilder::getInstance();
$moduleManagerRepository = $moduleManagerBuilder->buildRepository();
$moduleManagerRepository->clearCache();

try {
/**
* @var \PrestaShop\PrestaShop\Adapter\Module\AdminModuleDataProvider $modulesProvider
*/
$modulesProvider = $this->get('prestashop.core.admin.data_provider.module_interface');
} catch (Exception $e) {
$modulesProvider = null;
}
if ($modulesProvider) {
$modulesProvider->clearCatalogCache();
}

$cacheProvider->save($cacheKey, true, 86400);
}
}

/**
Expand Down

0 comments on commit a00b3f9

Please sign in to comment.