Skip to content

Commit

Permalink
OXDEV-7768 Remove Template cache service
Browse files Browse the repository at this point in the history
  • Loading branch information
AshrafOxid committed Apr 19, 2024
1 parent 1b8b682 commit 045eb0b
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 330 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG-8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
- Remove deprecated global function \makeReadable()
- Redundant `TemplateFileResolverInterface` functionality
- Smarty templates support
- `PAYMENT_INFO_OFF` translation [#0006426](https://bugs.oxid-esales.com/view.php?id=6426) [PR-953](https://github.com/OXID-eSales/oxideshop_ce/pull/953)
- `PAYMENT_INFO_OFF` translation [#0006426](https://bugs.oxid-esales.com/view.php?id=6426) [PR-953](https://github.com/OXID-eSales/oxideshop_ce/pull/953)
- Remove deprecated `TemplateCacheService` implementation
14 changes: 7 additions & 7 deletions source/Internal/Framework/Cache/Command/ClearCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Service\ContainerCacheInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\ModuleCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\TemplateCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
use Symfony\Component\Console\Command\Command;
Expand All @@ -16,11 +16,11 @@
class ClearCacheCommand extends Command
{
public function __construct(
private ShopAdapterInterface $shopAdapter,
private TemplateCacheServiceInterface $templateCacheService,
private ContainerCacheInterface $containerCache,
private ModuleCacheServiceInterface $moduleCacheService,
private ContextInterface $context
private readonly ShopAdapterInterface $shopAdapter,
private readonly ShopTemplateCacheServiceInterface $shopTemplateCacheService,
private readonly ContainerCacheInterface $containerCache,
private readonly ModuleCacheServiceInterface $moduleCacheService,
private readonly ContextInterface $context
) {
parent::__construct();
}
Expand All @@ -32,7 +32,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->templateCacheService->invalidateTemplateCache();
$this->shopTemplateCacheService->invalidateAllShopsCache();
$this->shopAdapter->invalidateModulesCache();

foreach ($this->context->getAllShopIds() as $shopId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
class ShopTemplateCacheService implements ShopTemplateCacheServiceInterface
{
public function __construct(
private ContextInterface $context,
private Filesystem $filesystem
private readonly ContextInterface $context,
private readonly Filesystem $filesystem
) {
}

Expand Down

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions source/Internal/Framework/Templating/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ services:
arguments:
Symfony\Component\Filesystem\Filesystem: '@oxid_esales.symfony.file_system'

OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\TemplateCacheServiceInterface:
class: OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\TemplateCacheService
arguments:
- '@OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface'
- '@OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface'

OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface:
class: OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheService
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace OxidEsales\EshopCommunity\Internal\Framework\Theme\Command;

use OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\ModuleCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\TemplateCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -25,7 +25,7 @@ class ThemeActivateCommand extends Command

public function __construct(
private readonly ShopAdapterInterface $shopAdapter,
private readonly TemplateCacheServiceInterface $templateCacheService,
private readonly ShopTemplateCacheServiceInterface $shopTemplateCacheService,
private readonly ModuleCacheServiceInterface $moduleCacheService
) {
parent::__construct();
Expand Down Expand Up @@ -58,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->shopAdapter->activateTheme($themeId);
$this->moduleCacheService->invalidateAll();
$this->templateCacheService->invalidateTemplateCache();
$this->shopTemplateCacheService->invalidateAllShopsCache();
$output->writeLn('<info>' . sprintf(self::MESSAGE_THEME_ACTIVATED, $themeId) . '</info>');

return Command::SUCCESS;
Expand Down
8 changes: 0 additions & 8 deletions source/Internal/Transition/Utility/BasicContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,4 @@ public function getFacts(): Facts
}
return $this->facts;
}

public function getTemplateCacheDirectory(): string
{
return Path::join(
$this->getCacheDirectory(),
'template_cache'
);
}
}
5 changes: 0 additions & 5 deletions source/Internal/Transition/Utility/BasicContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,4 @@ public function getFacts(): Facts;
public function getCacheDirectory(): string;

public function getModuleCacheDirectory(): string;

/**
* @deprecated Use OxidEsales\Eshop\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface instead
*/
public function getTemplateCacheDirectory(): string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\EshopCommunity\Tests\Integration\Internal\Framework\Templating\Cache;

use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use OxidEsales\EshopCommunity\Tests\TestContainerFactory;
use OxidEsales\EshopCommunity\Tests\Unit\Internal\ContextStub;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Path;

final class MultiShopTemplateCacheServiceTest extends TestCase
{
use ContainerTrait;

private string $testFixturesDirectory = __DIR__ . '/cache_fixtures';
private int $shopId1 = 123;
private int $shopId2 = 456;
private array $allShopIds = [];
private array $cacheFixturesForShopId = [];

public function setUp(): void
{
parent::setUp();

$this->allShopIds = [
$this->shopId1,
$this->shopId2,
];
$this->stubContext();
$this->generateCacheFixtures();
}

public function tearDown(): void
{
$this->cleanupCache();

parent::tearDown();
}

public function testInvalidateCacheWillKeepOtherShopsCacheFile(): void
{
$this->get(ShopTemplateCacheServiceInterface::class)->invalidateCache($this->shopId1);

$this->assertFileDoesNotExist($this->cacheFixturesForShopId[$this->shopId1]);
$this->assertFileExists($this->cacheFixturesForShopId[$this->shopId2]);
}

public function testInvalidateAllShopsCacheWillRemoveAllCacheFiles(): void
{
$this->get(ShopTemplateCacheServiceInterface::class)->invalidateAllShopsCache();

$this->assertFileDoesNotExist($this->cacheFixturesForShopId[$this->shopId1]);
$this->assertFileDoesNotExist($this->cacheFixturesForShopId[$this->shopId2]);
}

private function stubContext(): void
{
$context = new ContextStub();
$context->setCacheDirectory($this->testFixturesDirectory);
$context->setAllShopIds($this->allShopIds);

$this->container = (new TestContainerFactory())->create();
$this->container->set(ContextInterface::class, $context);
$this->container->autowire(ContextInterface::class, ContextInterface::class);
$this->container->compile();
}

private function generateCacheFixtures(): void
{
$filesystem = $this->get('oxid_esales.symfony.file_system');

foreach ($this->allShopIds as $shopId) {
$templateCacheDirectory = $this->get(ShopTemplateCacheServiceInterface::class)->getCacheDirectory($shopId);
$filesystem->mkdir($templateCacheDirectory);
$this->cacheFixturesForShopId[$shopId] = Path::join($templateCacheDirectory, 'some-cache-file');
$filesystem->touch($this->cacheFixturesForShopId[$shopId]);
}

$this->assertFileExists($this->cacheFixturesForShopId[$this->shopId1]);
$this->assertFileExists($this->cacheFixturesForShopId[$this->shopId2]);
}

private function cleanupCache(): void
{
$this->get('oxid_esales.symfony.file_system')->remove($this->testFixturesDirectory);
}
}

This file was deleted.

Loading

0 comments on commit 045eb0b

Please sign in to comment.