EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Data cache provider
Yurii1de121f00b8f
diff --git a/application/Espo/Core/DataManager.php b/application/Espo/Core/DataManager.phpindex 0a52156f4e..fd8d3f2eac 100644--- a/application/Espo/Core/DataManager.php+++ b/application/Espo/Core/DataManager.php@@ -33,6 +33,7 @@ use Espo\Core\Binding\Attributes\Qualify;use Espo\Core\Exceptions\Error;use Espo\Core\Hook\Control;use Espo\Core\ORM\EntityManagerProxy;+use Espo\Core\Utils\Cache\DataCacheProvider;use Espo\Core\Utils\Cache\Exceptions\PersistenceError;use Espo\Core\Utils\Database\Helper as DatabaseHelper;use Espo\Core\Utils\Database\Schema\RebuildMode;@@ -76,7 +77,7 @@ class DataManagerprivate Control $hookControl,#[Qualify(DataCache::QUALIFIER_SYSTEM)]private DataCache $systemDataCache,- private DataCache $dataCache,+ private DataCacheProvider $dataCacheProvider,) {}/**@@ -108,21 +109,24 @@ class DataManager{$this->module->clearCache();+ $result = $this->fileManager->removeInDir($this->cachePath);+try {$this->systemDataCache->clearAll();} catch (PersistenceError $e) {throw new Error("Could not clear system cache.", previous: $e);}- if ($this->systemDataCache !== $this->dataCache) {+ $dataCache = $this->dataCacheProvider->get();++ if ($this->systemDataCache !== $dataCache) {try {- $this->dataCache->clearAll();+ $dataCache->clearAll();} catch (PersistenceError $e) {throw new Error("Could not clear application cache.", previous: $e);}}- $result = $this->fileManager->removeInDir($this->cachePath);if (!$result) {throw new Error("Error while clearing cache.");diff --git a/application/Espo/Core/Utils/Cache/DataCacheProvider.php b/application/Espo/Core/Utils/Cache/DataCacheProvider.phpnew file mode 100644index 0000000000..4037e197fd--- /dev/null+++ b/application/Espo/Core/Utils/Cache/DataCacheProvider.php@@ -0,0 +1,52 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2026 EspoCRM, Inc.+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Core\Utils\Cache;++use Espo\Core\Container;+use Espo\Core\Utils\DataCache;++/**+ * May be needed when data cache is corrupted not allowing to load the DataCache service+ * when clearing cache.+ *+ * @internal+ * @since 10.1.0+ */+class DataCacheProvider+{+ public function __construct(+ private Container $container,+ ) {}++ public function get(): DataCache+ {+ return $this->container->getByClass(DataCache::class);+ }+}