def check_file_list_cache(opts, form, list_cache, w_lock):
    '''
    Checks the cache file to see if there is a new enough file list cache, and
    returns the match (if found, along with booleans used by the fileserver
    backend to determine if the cache needs to be refreshed/written).
    '''
    refresh_cache = False
    save_cache = True
    serial = salt.payload.Serial(opts)
    wait_lock(w_lock, list_cache, 5 * 60)
    if not os.path.isfile(list_cache) and _lock_cache(w_lock):
        refresh_cache = True
    else:
        attempt = 0
        while attempt < 11:
            try:
                if os.path.exists(w_lock):
                    # wait for a filelist lock for max 15min
                    wait_lock(w_lock, list_cache, 15 * 60)
                if os.path.exists(list_cache):
                    # calculate filelist age is possible
                    cache_stat = os.stat(list_cache)
                    # st_time can have a greater precision than time, removing
                    # float precision makes sure age will never be a negative
                    # number.
                    current_time = int(time.time())
                    file_mtime = int(cache_stat.st_mtime)
                    if file_mtime > current_time:
                        log.debug(
                            'Cache file modified time is in the future, ignoring. '
                            'file=%s mtime=%s current_time=%s',
                            list_cache, current_time, file_mtime
                        )
                        age = 0
                    else:
                        age = current_time - file_mtime
                else:
                    # if filelist does not exists yet, mark it as expired
                    age = opts.get('fileserver_list_cache_time', 20) + 1
                if age < 0:
                    # Cache is from the future! Warn and mark cache invalid.
                    log.warning('The file list_cache was created in the future!')
                if 0 <= age < opts.get('fileserver_list_cache_time', 20):
                    # Young enough! Load this sucker up!
                    with salt.utils.files.fopen(list_cache, 'rb') as fp_:
                        log.debug(
                            "Returning file list from cache: age=%s cache_time=%s %s",
                            age, opts.get('fileserver_list_cache_time', 20), list_cache
                        )
                        return salt.utils.data.decode(serial.load(fp_).get(form, [])), False, False
                elif _lock_cache(w_lock):
                    # Set the w_lock and go
                    refresh_cache = True
                    break
            except Exception:
                time.sleep(0.2)
                attempt += 1
                continue
        if attempt > 10:
            save_cache = False
            refresh_cache = True
    return None, refresh_cache, save_cache
Checks the cache file to see if there is a new enough file list cache, and
    returns the match (if found, along with booleans used by the fileserver
    backend to determine if the cache needs to be refreshed/written).