diff --git a/vendor/magento/module-target-rule/Model/ResourceModel/Index.php b/vendor/magento/module-target-rule/Model/ResourceModel/Index.php
index 3de9dc5d741f..dcaaa4dc2f88 100644
--- a/vendor/magento/module-target-rule/Model/ResourceModel/Index.php
+++ b/vendor/magento/module-target-rule/Model/ResourceModel/Index.php
@@ -235,6 +235,9 @@ public function getProductIds($object, $customerId = null, $websiteId = null)
 
             if (empty($matchedProductIds)) {
                 $matchedProductIds = $this->_matchProductIdsBySegmentId($object, $segmentId);
+                if (empty($matchedProductIds)) {
+                    continue;
+                }
                 $this->_indexPool->get($object->getType())
                     ->saveResultForCustomerSegments(
                         $object,
diff --git a/vendor/magento/module-target-rule/Model/ResourceModel/Index/Index.php b/vendor/magento/module-target-rule/Model/ResourceModel/Index/Index.php
index 717dbd86e4a4..6c6e35741a3a 100644
--- a/vendor/magento/module-target-rule/Model/ResourceModel/Index/Index.php
+++ b/vendor/magento/module-target-rule/Model/ResourceModel/Index/Index.php
@@ -16,10 +16,10 @@
  */
 class Index implements IndexInterface
 {
-    const CACHE_TAG_TYPE_ENTITY = 'entity';
-    const CACHE_TAG_TYPE_STORE = 'store';
-    const CACHE_TAG_TYPE_CUSTOMER_GROUP = 'customer_group';
-    const CACHE_TAG_TYPE_CUSTOMER_SEGMENT = 'customer_segment';
+    public const CACHE_TAG_TYPE_ENTITY = 'entity';
+    public const CACHE_TAG_TYPE_STORE = 'store';
+    public const CACHE_TAG_TYPE_CUSTOMER_GROUP = 'customer_group';
+    public const CACHE_TAG_TYPE_CUSTOMER_SEGMENT = 'customer_segment';
 
     /**
      * @var IndexCache
@@ -102,8 +102,6 @@ public function saveResultForCustomerSegments(IndexModel $indexModel, $segmentId
             if (!$this->cache->save($productIds, $cacheKey, $tags)) {
                 $this->cache->remove($cacheKey);
             }
-        } else {
-            $this->cache->remove($cacheKey);
         }
 
         return $this;
