tempjson
attributePathLike= str | os.PathLike[str]attributeVT= TypeVar('VT')attributetempjson_rw_lock= Lock()attributetempjson_pathsdict[PathLike, _jsonfile_status]= {}funcload_from_path(path, need_file_exists=True, default=None, unload_delay=None) -> _jsonfile_status将 json 文件从磁盘加载到缓存区,以便快速读写. 在缓存文件已加载的情况下,再使用一次该方法不会有任何作用.
Args: path (str): 作为文件的磁盘内路径的同时也会作为在缓存区的虚拟路径 needFileExists (bool, optional): 默认为 True, 为 False 时,若文件路径不存在,就会自动创建一个文件 default (Any, optional): 默认为 None, 为 None 时,若文件路径不存在,就会自动创建一个文件,且写入默认值 null unload_delay (int, optional): 多久没有再进行读写操作时, 将其从缓存卸载
Raises: err: 文件不存在时
parampathPathLikeparamneed_file_existsbool= TrueparamdefaultAny= Noneparamunload_delayint | None= NoneReturns
tooldelta.utils.tempjson._jsonfile_statusfuncunload_to_path(path) -> bool将 json 文件从缓存区卸载 (保存内容到磁盘), 之后不能再在缓存区对这个文件进行读写. 在缓存文件已卸载的情况下,再使用一次该方法不会有任何作用,但是可以通过其返回的值来知道存盘有没有成功.
Args: path (str): 文件的虚拟路径
Returns: bool: 存盘是否成功
parampathPathLikeReturns
boolfuncread(path, deepcopy=True)对缓存区的该虚拟路径的文件进行读操作,返回一个深拷贝的 JSON 对象
Args: path (str): 文件的虚拟路径
Raises: Exception: json 路径未初始化,不能进行读取和写入操作
Returns: list[Any] | dict[Any, Any] | Any: 该虚拟路径的 JSON
parampathPathLikeparamdeepcopybool= TrueReturns
Nonefuncget(path) -> Any直接获取缓存区的该虚拟路径的 JSON, 不使用 copy
WARNING: 如果你不知道有什么后果,请老老实实使用read(...)而不是get(...)!
Args: path (str): 文件的虚拟路径
parampathPathLikeReturns
typing.Anyfuncwrite(path, obj) -> None对缓存区的该虚拟路径的文件进行写操作,这将会覆盖之前的内容
Args: path (str): 文件的虚拟路径 obj (Any): 任何合法的 JSON 类型 例如 dict/list/str/bool/int/float
parampathPathLikeparamobjAnyReturns
Nonefuncload_and_read(path, need_file_exists=True, timeout=60, default={}) -> VT读取 json 文件并将其从磁盘加载到缓存区,以便一段时间内能快速读写.
Args: path (str): 作为文件的磁盘内路径的同时也会作为在缓存区的虚拟路径 needFileExists (bool, optional): 默认为 True, 为 False 时,若文件路径不存在,就会自动创建一个文件,且写入默认值 null timeout (int, optional): 多久没有再进行读取操作时卸载缓存 default (() -> Any | Any, optional):
Returns: Any: 该虚拟路径的 JSON
parampathPathLikeparamneed_file_existsbool= Trueparamtimeoutint= 60paramdefaultCallable[[], VT] | VT= {}Returns
tooldelta.utils.tempjson.VTfuncload_and_write(path, obj, need_file_exists=True, timeout=60) -> None写入 json 文件并将其从磁盘加载到缓存区,以便一段时间内能快速读写.
Args: path (str): 作为文件的磁盘内路径的同时也会作为在缓存区的虚拟路径 obj (Any): 任何合法的 JSON 类型 例如 dict/list/str/bool/int/float needFileExists (bool, optional): 默认为 True, 为 False 时,若文件路径不存在,就会自动创建一个文件,且写入默认值 null timeout (int, optional): 多久没有再进行读取操作时卸载缓存
parampathPathLikeparamobjAnyparamneed_file_existsbool= Trueparamtimeoutint= 60Returns
Nonefunccancel_change(path)取消缓存 json 所做的更改,非必要情况请勿调用,你不知道什么时候会自动保存所做更改
parampathstrReturns
Nonefuncflush(path=None)刷新单个/全部JSON缓存区的缓存文件, 存入磁盘
Args: path (str | None, optional): 文件虚拟路径, 默认全部存盘
parampathPathLike | None= NoneReturns
Nonefuncget_tmps() -> dict获取缓存区中所有临时文件
Returns
dictfuncjsonfile_auto_save()Returns
Nonefuncsave_all()Returns
Nonefuncreset()Returns
None