def cached_FS(save_fnc=None, load_fnc=None, check_fnc=None, skip_args=None, cache_ram=False, use_cPickle=False):
    if not skip_args:
        skip_args = {}

    def cached_HDD_inner(func):
        def func_caching(*args, **dict_args):
            """
            Use mmap only for files around 1/2 memory
            """
            if len(args) > 0:
                raise Exception("For cached_FS functions pass all args by dict_args (ensures cache resolution)")


            # ## Dump special arguments
            dict_args_original = dict(dict_args)
            dict_args_original.pop("use_mmap", None)
            dict_args_original.pop("force_reload", None)

            key, fullkey = generate_key(func.__name__, args, dict_args_original, skip_args)

            # For retrievel
            if not os.path.exists(os.path.join(c["CACHE_DIR"], "cache_dict.txt")):
                with open(os.path.join(c["CACHE_DIR"], "cache_dict.txt"),"w") as f:
                    f.write("File containing hashes explanation for refernce\n ==== \n")

            with open(os.path.join(c["CACHE_DIR"], "cache_dict.txt"),"a") as f:
                f.write(key + "\n" + fullkey +"\n")


            if cache_ram and key in mem_storage:
                print("Reading from cache ram")
                return mem_storage[key]

            logger.info("Checking key " + key)
            cache_file_default = os.path.join(c["CACHE_DIR"], str(key) + ".cache.pkl")
            exists = os.path.exists(cache_file_default) if check_fnc is None else check_fnc(key)
            if exists and not "force_reload" in dict_args:
                logger.info("Loading (pickled?) file")

                if load_fnc:
                    return load_fnc(key)
                else:
                    with open(cache_file_default, "r") as f:
                        if "use_mmap" in dict_args:
                            g = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)
                            obj = cPickle.load(g) if use_cPickle  else pickle.load(g)
                            g.close()
                            return obj
                        else:
                            obj = cPickle.load(f) if use_cPickle else pickle.load(f)
                            return obj
            else:
                logger.info("Cache miss or force reload. Caching " + key)
                returned_value = func(*args, **dict_args_original)
                if save_fnc:
                    save_fnc(key, returned_value)
                else:
                    with open(cache_file_default, "w") as f:
                        if use_cPickle:
                            cPickle.dump(returned_value, f)
                        else:
                            pickle.dump(returned_value, f)

                if cache_ram:
                    mem_storage[key] = returned_value

                return returned_value

        return func_caching

    return cached_HDD_inner
To make it work correctly please pass parameters to function as dict
dataset/ETHPy150Open kudkudak/learning-wordnet/utils.py/cached_FS