Skip to content

Commit a1a8f85

Browse files
authored
feat(run): support custom cache file (#376)
* feat(run): support custom cache file * fix cannot using C style conditional operator * fix lint * fix lint
1 parent 60a3aa2 commit a1a8f85

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ python run.py -c /path/to/config.json
131131
| ttl | number | No | `null` | DNS 解析 TTL 时间 | 不设置采用 DNS 默认策略 |
132132
| proxy | string | No || http 代理`;`分割 | 多代理逐个尝试直到成功,`DIRECT`为直连 |
133133
| debug | bool | No | `false` | 是否开启调试 | 运行异常时,打开调试输出,方便诊断错误 |
134-
| cache | bool | No | `true` | 是否缓存记录 | 正常情况打开避免频繁更新 |
134+
| cache | string\|bool | No | `true` | 是否缓存记录 | 正常情况打开避免频繁更新,默认位置为临时目录下`ddns.cache`,<br>也可以指定一个具体文件实现自定义文件缓存位置 |
135135

136136
#### index4 和 index6 参数说明
137137

run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
environ['SSL_CERT_FILE'] = path.join(
3535
getattr(sys, '_MEIPASS'), 'lib', 'cert.pem')
3636

37-
CACHE_FILE = path.join(gettempdir(), 'ddns.cache')
38-
3937

4038
def get_ip(ip_type, index="default"):
4139
"""
@@ -139,7 +137,9 @@ def main():
139137
proxy_list = proxy if isinstance(
140138
proxy, list) else proxy.strip('; ').replace(',', ';').split(';')
141139

142-
cache = get_config('cache', True) and Cache(CACHE_FILE)
140+
cache = get_config('cache', True)
141+
cache = cache is True and path.join(gettempdir(), 'ddns.cache') or cache
142+
cache = Cache(cache)
143143
if cache is False:
144144
info("Cache is disabled!")
145145
elif get_config("config_modified_time") is None or get_config("config_modified_time") >= cache.time:

schema/v2.8.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,17 @@
186186
},
187187
"cache": {
188188
"$id": "/properties/cache",
189-
"type": "boolean",
189+
"type": [
190+
"string",
191+
"boolean"
192+
],
190193
"title": "Enable Cache",
191194
"description": "是否启用缓存记录以避免频繁更新",
192195
"default": true,
193196
"examples": [
194197
true,
195-
false
198+
false,
199+
"/path/to/cache/ddns.cache"
196200
]
197201
}
198202
},

0 commit comments

Comments
 (0)