def clear_cached_minion_data(self,
                                 clear_pillar=False,
                                 clear_grains=False,
                                 clear_mine=False,
                                 clear_mine_func=None):
        '''
        Clear the cached data/files for the targeted minions.
        '''
        clear_what = []
        if clear_pillar:
            clear_what.append('pillar')
        if clear_grains:
            clear_what.append('grains')
        if clear_mine:
            clear_what.append('mine')
        if clear_mine_func is not None:
            clear_what.append('mine_func: \'{0}\''.format(clear_mine_func))
        if not len(clear_what):
            log.debug('No cached data types specified for clearing.')
            return False

        minion_ids = self._tgt_to_list()
        log.debug('Clearing cached {0} data for: {1}'.format(
            ', '.join(clear_what),
            minion_ids))
        if clear_pillar == clear_grains:
            # clear_pillar and clear_grains are both True or both False.
            # This means we don't deal with pillar/grains caches at all.
            grains = {}
            pillars = {}
        else:
            # Unless both clear_pillar and clear_grains are True, we need
            # to read in the pillar/grains data since they are both stored
            # in the same file, 'data.p'
            grains, pillars = self._get_cached_minion_data(*minion_ids)
        try:
            for minion_id in minion_ids:
                if not salt.utils.verify.valid_id(self.opts, minion_id):
                    continue
                cdir = os.path.join(self.opts['cachedir'], 'minions', minion_id)
                if not os.path.isdir(cdir):
                    # Cache dir for this minion does not exist. Nothing to do.
                    continue
                data_file = os.path.join(cdir, 'data.p')
                mine_file = os.path.join(cdir, 'mine.p')
                minion_pillar = pillars.pop(minion_id, False)
                minion_grains = grains.pop(minion_id, False)
                if ((clear_pillar and clear_grains) or
                    (clear_pillar and not minion_grains) or
                    (clear_grains and not minion_pillar)):
                    # Not saving pillar or grains, so just delete the cache file
                    os.remove(os.path.join(data_file))
                elif clear_pillar and minion_grains:
                    tmpfh, tmpfname = tempfile.mkstemp(dir=cdir)
                    os.close(tmpfh)
                    with salt.utils.fopen(tmpfname, 'w+b') as fp_:
                        fp_.write(self.serial.dumps({'grains': minion_grains}))
                    salt.utils.atomicfile.atomic_rename(tmpfname, data_file)
                elif clear_grains and minion_pillar:
                    tmpfh, tmpfname = tempfile.mkstemp(dir=cdir)
                    os.close(tmpfh)
                    with salt.utils.fopen(tmpfname, 'w+b') as fp_:
                        fp_.write(self.serial.dumps({'pillar': minion_pillar}))
                    salt.utils.atomicfile.atomic_rename(tmpfname, data_file)
                if clear_mine:
                    # Delete the whole mine file
                    os.remove(os.path.join(mine_file))
                elif clear_mine_func is not None:
                    # Delete a specific function from the mine file
                    with salt.utils.fopen(mine_file, 'rb') as fp_:
                        mine_data = self.serial.loads(fp_.read())
                    if isinstance(mine_data, dict):
                        if mine_data.pop(clear_mine_func, False):
                            tmpfh, tmpfname = tempfile.mkstemp(dir=cdir)
                            os.close(tmpfh)
                            with salt.utils.fopen(tmpfname, 'w+b') as fp_:
                                fp_.write(self.serial.dumps(mine_data))
                            salt.utils.atomicfile.atomic_rename(
                                tmpfname,
                                mine_file)
        except (OSError, __HOLE__):
            return True
        return True
dataset/ETHPy150Open saltstack/salt/salt/utils/master.py/MasterPillarUtil.clear_cached_minion_data