title: Magento 2 Rest Api is clearing cache too frequently on product updates
body: <p>We have an issue with Magento 2's Api regarding the full page cache and updates from the rest API from our ERP system. The ERP is constantly pushing inventory, stock and product updates through the API and in turn this flushes the cache for every product update resulting in a consistently non-cached website. We tried to wrap around the FlushCacheByTags class to prevent rest calls from flushing the cache. This seems to be getting hit but the cache is still being cleared. Here is the class override:</p>
  
  <pre><code>&lt;?php
  /**
   *
   * Copyright © 2016 Magento. All rights reserved.
   * See COPYING.txt for license details.
   */
  namespace Namespace\Module\Magento\Framework\App\Cache;
  
  /**
  * Automatic cache cleaner plugin
  */
  class FlushCacheByTags extends 
  \Magento\Framework\App\Cache\FlushCacheByTags
  {
  
  /**
   * @var \Psr\Log\LoggerInterface
   */
  protected $_logger;
  
  /**
   * FlushCacheByTags constructor.
   * @param \Magento\Framework\App\Cache\Type\FrontendPool $cachePool
   * @param \Magento\Framework\App\Cache\StateInterface $cacheState
   * @param array $cacheList
   * @param null $tagResolver
   * @param \Psr\Log\LoggerInterface $_logger
   */
  public function __construct(
      \Magento\Framework\App\Cache\Type\FrontendPool $cachePool,
      \Magento\Framework\App\Cache\StateInterface $cacheState,
      array $cacheList,
      \Psr\Log\LoggerInterface $_logger,
      $tagResolver = null
  
  )
  {
      parent::__construct($cachePool, $cacheState, $cacheList, $tagResolver);
      $this-&gt;_logger = $_logger;
  }
  
  /**
   * Clean cache on save object
   *
   * @param \Magento\Framework\Model\ResourceModel\AbstractResource $subject
   * @param \Closure $proceed
   * @param \Magento\Framework\Model\AbstractModel $object
   * @return \Magento\Framework\Model\ResourceModel\AbstractResource
   * @SuppressWarnings(PHPMD.UnusedFormalParameter)
   */
  public function aroundSave(
      \Magento\Framework\Model\ResourceModel\AbstractResource $subject,
      \Closure $proceed,
      \Magento\Framework\Model\AbstractModel $object
  ) {
      $this-&gt;_logger-&gt;debug('CACHE SAVE - instance of: '. print_r(get_class($object),true));
  
      if (
              // is instance of
              /* @var $object \Magento\Catalog\Model\Product */
              $object instanceof \Magento\Catalog\Model\Product
          &amp;&amp; (
              // is rest api request
              isset($_SERVER['REQUEST_URI']) &amp;&amp; strpos($_SERVER['REQUEST_URI'],'/rest') === 0
              )
          &amp;&amp; (
              // has data
              !empty($object-&gt;getData())
          )
      ) {
          $this-&gt;_logger-&gt;debug('Cache NOT flushed from API SKU#: '.print_r($object-&gt;getSku(),true));
          return $proceed($object);
      }
  
      return parent::aroundSave($subject, $proceed, $object);
  }
  
  /**
   * Clean cache on delete object
   *
   * @param \Magento\Framework\Model\ResourceModel\AbstractResource $subject
   * @param \Closure $proceed
   * @param \Magento\Framework\Model\AbstractModel $object
   * @return \Magento\Framework\Model\ResourceModel\AbstractResource
   * @SuppressWarnings(PHPMD.UnusedFormalParameter)
   */
  public function aroundDelete(
      \Magento\Framework\Model\ResourceModel\AbstractResource $subject,
      \Closure $proceed,
      \Magento\Framework\Model\AbstractModel $object
  ) {
      $this-&gt;_logger-&gt;debug('CACHE DELETE - instance of: '. print_r(get_class($object),true));
  
      if (
          // is instance of
          /* @var $object \Magento\Catalog\Model\Product */
          $object instanceof \Magento\Catalog\Model\Product
          &amp;&amp; (
              // is rest api request
  
              isset($_SERVER['REQUEST_URI']) &amp;&amp; strpos($_SERVER['REQUEST_URI'],'/rest') === 0
          )
      ){
          $this-&gt;_logger-&gt;debug('Cache NOT flushed from API SKU#: '.print_r($object-&gt;getSku(),true));
          return $proceed($object);
      }
      return parent::aroundDelete($subject, $proceed, $object);
  }
  }
  </code></pre>
  
  <p>Are we missing something here? We would like to be able to push data to the database via the API and handle the flush on our own accord not every tima a product is updated via the API. We have implement a cache warmer to try and counter act the flushes but it can not keep up with the frequency at which the cache is flushed. </p>
  
  <p>Here is what I am seeing in the logs on a product update from the API</p>
  
  <pre><code>[2017-06-09 21:26:05] report.DEBUG: CACHE SAVE - instance of: 
  Magento\Catalog\Model\Product\Interceptor {"is_exception":false} []
  
  [2017-06-09 21:26:05] report.DEBUG: Cache NOT flushed from API SKU#: 
  270876 {"is_exception":false} []
  
  [2017-06-09 21:26:05] report.DEBUG: cache_invalidate {"method":"PUT","url":"https://obscuredforsecurity.com/rest/all/V1/products/270876","invalidateInfo":{"tags":["catalog_product_0"],"mode":"matchingAnyTag"},"is_exception":false} []
  </code></pre>