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 Mar 25, 2024
1 parent db2d95d commit a54fe9b
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 219 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
- Remove deprecated global function \makeReadable()
- Redundant `TemplateFileResolverInterface` functionality
- Smarty templates support
- 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
Expand Up @@ -21,7 +21,6 @@ final class ShopTemplateCacheServiceTest extends TestCase
use ContainerTrait;

private int $shopId;
private array $shopsIds;
private string $shopTemplateCachePath;
private Filesystem $filesystem;
private ShopTemplateCacheServiceInterface $shopTemplateCacheService;
Expand All @@ -30,7 +29,6 @@ protected function setUp(): void
{
$this->filesystem = new Filesystem();
$this->shopId = $this->get(ContextInterface::class)->getCurrentShopId();
$this->shopsIds = $this->get(ContextInterface::class)->getAllShopIds();
$this->shopTemplateCachePath = $this->get(ShopTemplateCacheServiceInterface::class)
->getCacheDirectory($this->shopId);

Expand All @@ -49,55 +47,30 @@ public function testInvalidateCache(): void
$this->assertEquals(0, $this->countShopCacheFiles($this->shopId));
}

public function testInvalidateAllShopsCache(): void
{
$this->assertNotEquals(0, $this->countCacheFiles());

$this->get(ShopTemplateCacheServiceInterface::class)->invalidateAllShopsCache();

$this->assertEquals(0, $this->countCacheFiles());
}

private function clearTemplateCache(): void
{
foreach ($this->shopsIds as $shopId) {
$this->filesystem->remove(
$this->get(ShopTemplateCacheServiceInterface::class)
->getCacheDirectory($shopId)
);
}
$this->filesystem->remove(
$this->get(ShopTemplateCacheServiceInterface::class)->getCacheDirectory($this->shopId)
);
}

private function countShopCacheFiles($shopId): int
{
return count(\glob($this->get(ShopTemplateCacheServiceInterface::class)
->getCacheDirectory($shopId)));
}

private function countCacheFiles(): int
{
$files = 0;
foreach ($this->shopsIds as $shopId) {
$files += $this->countShopCacheFiles($shopId);
}
return $files;
return count(\glob($this->get(ShopTemplateCacheServiceInterface::class)->getCacheDirectory($shopId)));
}

private function populateTemplateCache(): void
{
$numberOfTestFiles = 3;
foreach ($this->shopsIds as $shopId) {
$templateCachePath = $this->get(ShopTemplateCacheServiceInterface::class)
->getCacheDirectory($shopId);
$this->filesystem->mkdir($templateCachePath);
for ($i = 0; $i < $numberOfTestFiles; $i++) {
$this->filesystem->touch(
Path::join(
$templateCachePath,
uniqid('template-file-' . $shopId, true)
)
);
}
$templateCachePath = $this->get(ShopTemplateCacheServiceInterface::class)->getCacheDirectory($this->shopId);
$this->filesystem->mkdir($templateCachePath);
for ($i = 0; $i < $numberOfTestFiles; $i++) {
$this->filesystem->touch(
Path::join(
$templateCachePath,
uniqid('template-file-' . $this->shopId, true)
)
);
}
}
}

This file was deleted.

7 changes: 0 additions & 7 deletions tests/Unit/Internal/BasicContextStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class BasicContextStub implements BasicContextInterface
private string $composerVendorName;
private string $cacheDirectory;
private string $moduleCacheDirectory;
private string $templateCacheDirectory;
private int $currentShopId;
private string $activeModuleServicesFilePath;

Expand All @@ -64,7 +63,6 @@ public function __construct()
$this->composerVendorName = $basicContext->getComposerVendorName();
$this->cacheDirectory = $basicContext->getCacheDirectory();
$this->moduleCacheDirectory = $basicContext->getModuleCacheDirectory();
$this->templateCacheDirectory = $basicContext->getTemplateCacheDirectory();
$this->currentShopId = $basicContext->getCurrentShopId();
$this->activeModuleServicesFilePath = $basicContext->getActiveModuleServicesFilePath($this->getCurrentShopId());
$this->shopConfigurableServicesFilePath = $basicContext->getShopConfigurableServicesFilePath(
Expand Down Expand Up @@ -237,11 +235,6 @@ public function getShopConfigurationDirectory(int $shopId): string
return Path::join($this->getProjectConfigurationDirectory(), 'shops', (string)$shopId);
}

public function getTemplateCacheDirectory(): string
{
return $this->templateCacheDirectory;
}

public function setTemplateCacheDirectory(string $templateCacheDirectory): void
{
$this->templateCacheDirectory = $templateCacheDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use OxidEsales\EshopCommunity\Internal\Framework\Cache\Command\ClearCacheCommand;
use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Service\ContainerCacheInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\ModuleCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\TemplateCacheService;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
use PHPUnit\Framework\TestCase;
Expand All @@ -26,8 +26,8 @@ public function testClearCacheTriggersRegularAndTemplatesCleaners(): void
$shopAdapterMock = $this->createMock(ShopAdapterInterface::class);
$shopAdapterMock->expects($this->once())->method('invalidateModulesCache');

$templateCacheServiceMock = $this->createMock(TemplateCacheService::class);
$templateCacheServiceMock->expects($this->once())->method('invalidateTemplateCache');
$shopTemplateCacheServiceMock = $this->createMock(ShopTemplateCacheServiceInterface::class);
$shopTemplateCacheServiceMock->expects($this->once())->method('invalidateAllShopsCache');

$containerCacheMock = $this->createMock(ContainerCacheInterface::class);
$containerCacheMock->expects($this->once())->method('invalidate');
Expand All @@ -40,7 +40,7 @@ public function testClearCacheTriggersRegularAndTemplatesCleaners(): void

$command = new ClearCacheCommand(
$shopAdapterMock,
$templateCacheServiceMock,
$shopTemplateCacheServiceMock,
$containerCacheMock,
$moduleCacheServiceMock,
$contextMock
Expand Down
Loading

0 comments on commit a54fe9b

Please sign in to comment.