Skip to content

[Framework] Fixing the caches that don't have no instance configured #26236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/internal/Magento/Framework/App/Cache/TypeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\SerializerInterface;

/**
* Class TypeList
*
* Caching types list
*/
class TypeList implements TypeListInterface
{
const INVALIDATED_TYPES = 'core_cache_invalidate';
Expand Down Expand Up @@ -132,7 +137,7 @@ public function getTypes()
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getTypeLabels()
{
Expand Down Expand Up @@ -191,7 +196,12 @@ public function invalidate($typeCode)
*/
public function cleanType($typeCode)
{
$this->_getTypeInstance($typeCode)->clean();
$typeInstance = $this->_getTypeInstance($typeCode);

if ($typeInstance) {
$typeInstance->clean();
}

$types = $this->_getInvalidatedTypes();
unset($types[$typeCode]);
$this->_saveInvalidatedTypes($types);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ public function testInvalidateList()
$this->_typeList->invalidate([self::TYPE_KEY]);
}

public function testCleanType()
/**
* @dataProvider cacheTypeConfigDataProvider
*
* @param array $cacheConfig
*/
public function testCleanType(array $cacheConfig)
{
$this->serializerMock->expects($this->once())
->method('unserialize')
Expand All @@ -173,7 +178,7 @@ public function testCleanType()
$this->returnValue('serializedData')
);
$this->_config->expects($this->once())->method('getType')->with(self::TYPE_KEY)->will(
$this->returnValue(['instance' => self::CACHE_TYPE])
$this->returnValue($cacheConfig)
);
unset($this->_typesArray[self::TYPE_KEY]);
$this->serializerMock->expects($this->once())
Expand All @@ -187,6 +192,25 @@ public function testCleanType()
$this->_typeList->cleanType(self::TYPE_KEY);
}

/**
* Cache config provider
*
* @return array
*/
public function cacheTypeConfigDataProvider(): array
{
return [
[
[
'instance' => self::CACHE_TYPE
],
],
[
[]
]
];
}

/**
* Returns prepared type
*
Expand Down