The article “flush cache and reindex programatically in magento 2” which will be help you to flush cache and reindexing magento 2 programatically . I have also posted same article for magento 1 reindexing-magento-programmatically . Flushing cache and reindexing programmatically