VWED_server/docs/sc/缓存数据相关.md

76 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 全局缓存数据
#### 获取缓存数据
- **方法说明**
**由于 VWED在线脚本里无法使用全局变量我们推荐如下方式缓存变量值。**
根据已缓存的 key 获取缓存数据。
```python
async def get_cache_param(key: str) -> str | None
```
- **输入参数**
- `key`:缓存键。
- **输出参数**
- 字符串类型JSON 格式。如果数据不存在,将返回 `None`
- **异常**
- 本方法会抛出异常。
#### 缓存数据
- **方法说明**
将参数中的 key 和 value 键值对在系统中进行缓存,缓存的数据将持久化,之后可通过 `get_cache_param` 方法根据 key 获取对应的 value。
```python
async def put_cache_param(key: str, value: str) -> None
```
- **输入参数**
- `key`:缓存键。
- `value`:缓存值。如果要缓存一个对象,需要先序列化为 JSON 字符串。
- **输出参数**
- 无。
- **异常**
- 本方法不会抛出异常。
#### 删除缓存数据
- **方法说明**
删除缓存数据。
```python
async def clear_cache_param(key: str) -> None
```
- **输入参数**
- `key`:缓存键。
- **输出参数**
- 无。
- **异常**
- 本方法不抛出异常。
#### 获取所有的缓存数据
- **方法说明**
获取缓存块的全部缓存数据,并以 JSON 格式返回。
```python
async def get_all_cache_params() -> str
```
- **输入参数**
- 无。
- **输出参数**
- 字符串类型JSON 格式。如果数据不存在,将返回空字符串。
- **异常**
- 本方法会抛出异常。