Skip to content

Commit

Permalink
OXDEV-7541 Introduce new cache interface and update module cache logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kenariosz committed May 22, 2024
1 parent 951b05d commit b387475
Show file tree
Hide file tree
Showing 33 changed files with 410 additions and 495 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
/source/export/*
!/source/export/.gitkeep

# Temporary files
!/source/tmp/
/source/tmp/*
!/source/tmp/.htaccess

# Composer
/vendor/
/composer.lock
Expand Down
20 changes: 15 additions & 5 deletions CHANGELOG-8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@
## v8.0.0 - unreleased

### Added

- Set custom product low stock label [#0004401](https://bugs.oxid-esales.com/view.php?id=4401)
- Support PSR caching interface and related functionalities and applied them on module cache.

### Changed
- Admin directory is not removed from the url in `ViewConfig::getModuleUrl` anymore [PR-817](https://github.com/OXID-eSales/oxideshop_ce/pull/817)
- Reset created product "sold" counter during Copying of the product [PR-913](https://github.com/OXID-eSales/oxideshop_ce/pull/913)

- Admin directory is not removed from the url in `ViewConfig::getModuleUrl`
anymore [PR-817](https://github.com/OXID-eSales/oxideshop_ce/pull/817)
- Reset created product "sold" counter during Copying of the
product [PR-913](https://github.com/OXID-eSales/oxideshop_ce/pull/913)
- `ModuleConfigurationValidatorInterface` is not optional anymore in the module activation service.
- The visibility of time-activated products has changed, products with an undefined end date appear in the shop for an unlimited period of time
- The visibility of time-activated products has changed, products with an undefined end date appear in the shop for an
unlimited period of time

### Removed
- Remove console classes from the Internal namespace: `Executor`, `ExecutorInterface`, `CommandsProvider`, `CommandsProviderInterface`

- Remove console classes from the Internal
namespace: `Executor`, `ExecutorInterface`, `CommandsProvider`, `CommandsProviderInterface`
- Cleanup deprecated Private Sales Invite functionality
- `getContainer()` and `dispatchEvent()` methods from Core classes
- 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
- Obsolete caching related functionalities
24 changes: 10 additions & 14 deletions source/Internal/Framework/Cache/Command/ClearCacheCommand.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php

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

declare(strict_types=1);

namespace OxidEsales\EshopCommunity\Internal\Framework\Cache\Command;

use OxidEsales\EshopCommunity\Internal\Framework\Cache\ShopCacheCleanerInterface;
use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Service\ContainerCacheInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\ModuleCacheServiceInterface;
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;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -16,11 +19,9 @@
class ClearCacheCommand extends Command
{
public function __construct(
private readonly ShopAdapterInterface $shopAdapter,
private readonly ShopTemplateCacheServiceInterface $shopTemplateCacheService,
private readonly ContainerCacheInterface $containerCache,
private readonly ModuleCacheServiceInterface $moduleCacheService,
private readonly ContextInterface $context
private readonly ContextInterface $context,
private readonly ShopCacheCleanerInterface $shopCacheCleaner,
) {
parent::__construct();
}
Expand All @@ -32,16 +33,11 @@ protected function configure(): void

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

$this->shopCacheCleaner->clearAll();
foreach ($this->context->getAllShopIds() as $shopId) {
$this->containerCache->invalidate($shopId);
}

$this->moduleCacheService->invalidateAll();

$output->writeln("<info>Cleared cache files</info>");
$output->writeln('<info>Cleared cache files</info>');

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

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

namespace OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool;

use Psr\Cache\CacheItemPoolInterface;

interface CacheItemPoolFactoryInterface
{
public function create(int $shopId): CacheItemPoolInterface;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

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

declare(strict_types=1);

namespace OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool;

use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Filesystem\Path;

class FilesystemCacheItemPoolFactory implements CacheItemPoolFactoryInterface
{
public function __construct(private readonly ContextInterface $context)
{
}

public function create(int $shopId): CacheItemPoolInterface
{
return new FilesystemAdapter(
namespace: "cache_items_shop_$shopId",
directory: Path::join($this->context->getCacheDirectory(), 'pool',)
);
}
}
10 changes: 10 additions & 0 deletions source/Internal/Framework/Cache/Pool/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
_defaults:
autowire: true

OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\CacheItemPoolFactoryInterface:
class: OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\FilesystemCacheItemPoolFactory

Psr\Cache\CacheItemPoolInterface:
factory: ['@OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\CacheItemPoolFactoryInterface', 'create']
arguments: ['@=service("OxidEsales\\EshopCommunity\\Internal\\Transition\\Utility\\ContextInterface").getCurrentShopId()']
15 changes: 15 additions & 0 deletions source/Internal/Framework/Cache/ShopCacheCleanerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

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

namespace OxidEsales\EshopCommunity\Internal\Framework\Cache;

interface ShopCacheCleanerInterface
{
public function clear(int $shopId): void;

public function clearAll(): void;
}
42 changes: 42 additions & 0 deletions source/Internal/Framework/Cache/ShopCacheFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

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

declare(strict_types=1);

namespace OxidEsales\EshopCommunity\Internal\Framework\Cache;

use OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\CacheItemPoolFactoryInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;

class ShopCacheFacade implements ShopCacheCleanerInterface
{
public function __construct(
private readonly ContextInterface $context,
private readonly CacheItemPoolFactoryInterface $cacheItemPoolFactory,
private readonly ShopAdapterInterface $shopAdapter,
private readonly ShopTemplateCacheServiceInterface $templateCacheService,
) {
}

public function clear(int $shopId): void
{
$this->shopAdapter->invalidateModulesCache();
$this->templateCacheService->invalidateCache($shopId);
$this->cacheItemPoolFactory->create($shopId)->clear();
}

public function clearAll(): void
{
$this->shopAdapter->invalidateModulesCache();
$this->templateCacheService->invalidateAllShopsCache();
foreach ($this->context->getAllShopIds() as $shopId) {
$this->cacheItemPoolFactory->create($shopId)->clear();
}
}
}
11 changes: 10 additions & 1 deletion source/Internal/Framework/Cache/services.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
imports:
- { resource: Command/services.yaml }
- { resource: Pool/services.yaml }
- { resource: Command/services.yaml }

services:
_defaults:
autowire: true

OxidEsales\EshopCommunity\Internal\Framework\Cache\ShopCacheCleanerInterface:
class: OxidEsales\EshopCommunity\Internal\Framework\Cache\ShopCacheFacade
public: true
17 changes: 10 additions & 7 deletions source/Internal/Framework/DIContainer/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function getContainer(): SymfonyContainerBuilder
$symfonyContainer = new SymfonyContainerBuilder();
$symfonyContainer->addCompilerPass(new RegisterListenersPass());
$symfonyContainer->addCompilerPass(new AddConsoleCommandPass());

$symfonyContainer->setParameter('oxid_cache_directory', $this->context->getCacheDirectory());

$this->loadEditionServices($symfonyContainer);
$this->loadModuleServices($symfonyContainer);
$this->loadProjectServices($symfonyContainer);
Expand Down Expand Up @@ -115,13 +118,13 @@ private function loadModuleServices(SymfonyContainerBuilder $symfonyContainer):
//no active modules, do nothing.
} catch (LoaderLoadException $exception) {
$loggerServiceFactory = new LoggerServiceFactory(new Context());
$logger = $loggerServiceFactory->getLogger();
// phpcs:disable
$logger->error(
"Can't load module services file path $moduleServicesFilePath. Please check if file exists and all imports in the file are correct.",
[$exception]
);
// phpcs:enable
$loggerServiceFactory
->getLogger()
->error(
"Can't load module services file path $moduleServicesFilePath.
Please check if file exists and all imports in the file are correct.",
[$exception]
);
}
}

Expand Down
Loading

0 comments on commit b387475

Please sign in to comment.