Skip to content

Commit 395446f

Browse files
committed
Clear results when start refreshing.
1 parent dc53b31 commit 395446f

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

Storage/AbstractStorage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public function update(string $identifier, array $data): bool
1313

1414
return $this->write($identifier, $newData);
1515
}
16+
17+
public function clear(string $identifier): bool
18+
{
19+
return $this->write($identifier, []);
20+
}
1621
}

Storage/StorageInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ public function read(string $identifier): array;
2020
* @param array<string, mixed> $data
2121
*/
2222
public function update(string $identifier, array $data): bool;
23+
24+
public function clear(string $identifier): bool;
2325
}

Test/Storage/CacheStorageTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,41 @@ public function testUpdatingExisting()
8585
$this->assertEquals($expectedData, $cacheStorage->read($identifier));
8686
}
8787

88+
public function testClear()
89+
{
90+
$identifier = 'identifier';
91+
$existingData = [
92+
'key1' => 'value1',
93+
'key2' => 'value2',
94+
];
95+
96+
$expectedData = [];
97+
98+
/** @var AppCache&MockObject */
99+
$cacheMock = $this
100+
->getMockBuilder(AppCache::class)
101+
->disableOriginalConstructor()
102+
->getMock();
103+
104+
$cacheMock->expects($this->exactly(2))
105+
->method('save')
106+
->withConsecutive(
107+
[$this->jsonEncode($existingData)],
108+
[$this->jsonEncode($expectedData)]
109+
)
110+
->willReturn(true);
111+
112+
$cacheMock->expects($this->exactly(1))
113+
->method('load')
114+
->willReturn($this->jsonEncode($expectedData));
115+
116+
$cacheStorage = new CacheStorage($cacheMock);
117+
$cacheStorage->write($identifier, $existingData);
118+
$cacheStorage->clear($identifier);
119+
120+
$this->assertEquals($expectedData, $cacheStorage->read($identifier));
121+
}
122+
88123
/**
89124
* @param array<string, string> $data
90125
*/

Updater/Catalog/Category/UrlKey.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function refresh(string $initiator): array
3939
throw new AlreadyRefreshingException($errorMsg);
4040
}
4141

42+
$this->storage->clear($storageIdentifier);
43+
4244
$this->metaStorage->setErrorMessage($storageIdentifier, '');
4345
$this->metaStorage->setStartRefreshing($storageIdentifier, $initiator);
4446

Updater/Catalog/Category/UrlPath.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function refresh(string $initiator): array
3939
throw new AlreadyRefreshingException($errorMsg);
4040
}
4141

42+
$this->storage->clear($storageIdentifier);
43+
4244
$this->metaStorage->setErrorMessage($storageIdentifier, '');
4345
$this->metaStorage->setStartRefreshing($storageIdentifier, $initiator);
4446

Updater/Catalog/Product/UrlKey.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function refresh(string $initiator): array
3939
throw new AlreadyRefreshingException($errorMsg);
4040
}
4141

42+
$this->storage->clear($storageIdentifier);
43+
4244
$this->metaStorage->setErrorMessage($storageIdentifier, '');
4345
$this->metaStorage->setStartRefreshing($storageIdentifier, $initiator);
4446

Updater/Catalog/Product/UrlPath.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function refresh(string $initiator): array
3939
throw new AlreadyRefreshingException($errorMsg);
4040
}
4141

42+
$this->storage->clear($storageIdentifier);
43+
4244
$this->metaStorage->setErrorMessage($storageIdentifier, '');
4345
$this->metaStorage->setStartRefreshing($storageIdentifier, $initiator);
4446

0 commit comments

Comments
 (0)