From 214bc838c235c8e7ac4d568f03447d02fa7fb7ac Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Sun, 11 Aug 2024 20:46:41 +0800 Subject: [PATCH] =?UTF-8?q?:memo:=20Docs:=20=E6=9B=B4=E6=96=B0=20localstor?= =?UTF-8?q?e=20=E6=8F=92=E4=BB=B6=E6=96=87=E6=A1=A3=20(#2871)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- website/docs/best-practice/data-storing.md | 66 +++++++++++++++++++--- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/website/docs/best-practice/data-storing.md b/website/docs/best-practice/data-storing.md index 0ff78a6d..d9f3a8c5 100644 --- a/website/docs/best-practice/data-storing.md +++ b/website/docs/best-practice/data-storing.md @@ -31,17 +31,17 @@ require("nonebot_plugin_localstore") import nonebot_plugin_localstore as store # 获取插件缓存目录 -cache_dir = store.get_cache_dir("plugin_name") +cache_dir = store.get_plugin_cache_dir() # 获取插件缓存文件 -cache_file = store.get_cache_file("plugin_name", "file_name") +cache_file = store.get_plugin_cache_file("file_name") # 获取插件数据目录 -data_dir = store.get_data_dir("plugin_name") +data_dir = store.get_plugin_data_dir() # 获取插件数据文件 -data_file = store.get_data_file("plugin_name", "file_name") +data_file = store.get_plugin_data_file("file_name") # 获取插件配置目录 -config_dir = store.get_config_dir("plugin_name") +config_dir = store.get_plugin_config_dir() # 获取插件配置文件 -config_file = store.get_config_file("plugin_name", "file_name") +config_file = store.get_plugin_config_file("file_name") ``` :::danger 警告 @@ -53,9 +53,61 @@ config_file = store.get_config_file("plugin_name", "file_name") ```python from pathlib import Path -data_file = store.get_data_file("plugin_name", "file_name") +data_file = store.get_plugin_data_file("file_name") # 写入文件内容 data_file.write_text("Hello World!") # 读取文件内容 data = data_file.read_text() ``` + +:::note 提示 + +对于嵌套插件,子插件的存储目录将位于父插件存储目录下。 + +::: + +## 配置项 + +### localstore_cache_dir + +自定义缓存目录 + +默认值: + +- macOS: `~/Library/Caches/` +- Unix: `~/.cache/` (XDG default) +- Windows: `C:\Users\\AppData\Local\\Cache` + +```dotenv +LOCALSTORE_CACHE_DIR=/tmp/cache +``` + +### localstore_data_dir + +自定义数据目录 + +默认值: + +- macOS: `~/Library/Application Support/` +- Unix: `~/.local/share/` or in $XDG_DATA_HOME, if defined +- Win XP (not roaming): `C:\Documents and Settings\\Application Data\` +- Win 7 (not roaming): `C:\Users\\AppData\Local\` + +```dotenv +LOCALSTORE_DATA_DIR=/tmp/data +``` + +### localstore_config_dir + +自定义配置目录 + +默认值: + +- macOS: same as user_data_dir +- Unix: `~/.config/` +- Win XP (roaming): `C:\Documents and Settings\\Local Settings\Application Data\` +- Win 7 (roaming): `C:\Users\\AppData\Roaming\` + +```dotenv +LOCALSTORE_CONFIG_DIR=/tmp/config +```