-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-7541 Introduce new cache interface and update module cache logic
- Loading branch information
Showing
33 changed files
with
410 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
source/Internal/Framework/Cache/Pool/CacheItemPoolFactoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
30 changes: 30 additions & 0 deletions
30
source/Internal/Framework/Cache/Pool/FilesystemCacheItemPoolFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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',) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
source/Internal/Framework/Cache/ShopCacheCleanerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.