BUG: Set / Delete the cache at the same time
- Dominant language
- PHP
- Stars
- 357
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
You are setting and deleting the cache at the same time
```
$this->stockItemDataCacheStorage->set(Stock::DEFAULT_STOCK_ID, $product->getSku(), $stockCache);
$this->stockItemDataCacheStorage->delete(Stock::DEFAULT_STOCK_ID, $product->getSku());
```
```
public function execute(Observer $observer)
{
/** @var Collection $productCollection */
$productCollection = $observer->getData('collection');
/** @var Product $product */
foreach ($productCollection->getItems() as $product) {
$this->productTypesBySkusStorage->set((string) $product->getSku(), (string) $product->getTypeId());
$this->productIdsBySkusStorage->set((string) $product->getSku(), (int) $product->getId());
$this->productSkusByIdsStorage->set((int) $product->getId(), (string) $product->getSku());
$stockData = $this->stockRegistry->getStockItemBySku($product->getSku());
$stockCache = ['quantity' => $stockData->getQty(), 'is_salable' => $stockData->getIsInStock()];
$this->stockItemDataCacheStorage->set(Stock::DEFAULT_STOCK_ID, $product->getSku(), $stockCache);
$this->stockItemDataCacheStorage->delete(Stock::DEFAULT_STOCK_ID, $product->getSku());
$this->cacheStorage->delete(Stock::DEFAULT_STOCK_ID, $product->getSku());
}
$productIds = array_keys($productCollection->getItems());
if ($productIds) {
$this->legacyStockStatusCache->execute($productIds);
}
}
```
For full code: https://github.com/magento/inventory/blob/develop/InventoryCatalog/Observer/PreloadCache.php#L105-L106
Contributor guide
Research direction
Open InventoryCatalog/Observer/PreloadCache.php around lines 105-106 and inspect the cache operations in execute(). Confirm whether the same stock cache entry is set and then deleted during preload, then run the relevant InventoryCatalog tests. Done means the contradictory cache behavior is corrected and the affected cache value remains consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100