Skip to content

Commit

Permalink
OXDEV-8412 replace cache item pool
Browse files Browse the repository at this point in the history
  • Loading branch information
AshrafOxid committed Dec 5, 2024
1 parent 3cec9af commit df0f484
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

declare(strict_types=1);

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

use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
use Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
use Symfony\Component\Filesystem\Path;

class FilesystemCacheItemPoolFactory implements CacheItemPoolFactoryInterface
class FilesystemTagAwareAdapterFactory implements TagAwareAdapterFactoryInterface
{
public function __construct(private readonly ContextInterface $context)
{
Expand All @@ -24,7 +24,7 @@ public function create(int $shopId): TagAwareAdapterInterface
{
return new FilesystemTagAwareAdapter(
namespace: "cache_items_shop_$shopId",
directory: Path::join($this->context->getCacheDirectory(), 'pool')
directory: Path::join($this->context->getCacheDirectory(), 'adapter')
);
}
}
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\Adapter;

use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;

interface TagAwareAdapterFactoryInterface
{
public function create(int $shopId): TagAwareAdapterInterface;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ services:
_defaults:
autowire: true

OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\CacheItemPoolFactoryInterface:
class: OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\FilesystemCacheItemPoolFactory
OxidEsales\EshopCommunity\Internal\Framework\Cache\Adapter\TagAwareAdapterFactoryInterface:
class: OxidEsales\EshopCommunity\Internal\Framework\Cache\Adapter\FilesystemTagAwareAdapterFactory

Symfony\Component\Cache\Adapter\TagAwareAdapterInterface:
factory: ['@OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\CacheItemPoolFactoryInterface', 'create']
factory: ['@OxidEsales\EshopCommunity\Internal\Framework\Cache\Adapter\TagAwareAdapterFactoryInterface', 'create']
arguments: ['@=service("OxidEsales\\EshopCommunity\\Internal\\Transition\\Utility\\ContextInterface").getCurrentShopId()']

Psr\Cache\CacheItemPoolInterface:
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions source/Internal/Framework/Cache/ShopCacheFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace OxidEsales\EshopCommunity\Internal\Framework\Cache;

use OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\CacheItemPoolFactoryInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Cache\Adapter\TagAwareAdapterFactoryInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
Expand All @@ -18,7 +18,7 @@ class ShopCacheFacade implements ShopCacheCleanerInterface
{
public function __construct(
private readonly ContextInterface $context,
private readonly CacheItemPoolFactoryInterface $cacheItemPoolFactory,
private readonly TagAwareAdapterFactoryInterface $tagAwareAdapterFactory,
private readonly ShopAdapterInterface $shopAdapter,
private readonly ShopTemplateCacheServiceInterface $templateCacheService,
) {
Expand All @@ -28,15 +28,15 @@ public function clear(int $shopId): void
{
$this->shopAdapter->invalidateModulesCache();
$this->templateCacheService->invalidateCache($shopId);
$this->cacheItemPoolFactory->create($shopId)->clear();
$this->tagAwareAdapterFactory->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->tagAwareAdapterFactory->create($shopId)->clear();
}
}
}
2 changes: 1 addition & 1 deletion source/Internal/Framework/Cache/services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
imports:
- { resource: Pool/services.yaml }
- { resource: Adapter/services.yaml }
- { resource: Command/services.yaml }

services:
Expand Down

0 comments on commit df0f484

Please sign in to comment.