Skip to content

Commit

Permalink
feat(run): support custom cache file (#376)
Browse files Browse the repository at this point in the history
* feat(run): support custom cache file

* fix cannot using C style conditional operator

* fix lint

* fix lint
  • Loading branch information
laozhoubuluo authored Dec 4, 2022
1 parent 60a3aa2 commit a1a8f85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ python run.py -c /path/to/config.json
| ttl | number | No | `null` | DNS 解析 TTL 时间 | 不设置采用 DNS 默认策略 |
| proxy | string | No || http 代理`;`分割 | 多代理逐个尝试直到成功,`DIRECT`为直连 |
| debug | bool | No | `false` | 是否开启调试 | 运行异常时,打开调试输出,方便诊断错误 |
| cache | bool | No | `true` | 是否缓存记录 | 正常情况打开避免频繁更新 |
| cache | string\|bool | No | `true` | 是否缓存记录 | 正常情况打开避免频繁更新,默认位置为临时目录下`ddns.cache`,<br>也可以指定一个具体文件实现自定义文件缓存位置 |

#### index4 和 index6 参数说明

Expand Down
6 changes: 3 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
environ['SSL_CERT_FILE'] = path.join(
getattr(sys, '_MEIPASS'), 'lib', 'cert.pem')

CACHE_FILE = path.join(gettempdir(), 'ddns.cache')


def get_ip(ip_type, index="default"):
"""
Expand Down Expand Up @@ -139,7 +137,9 @@ def main():
proxy_list = proxy if isinstance(
proxy, list) else proxy.strip('; ').replace(',', ';').split(';')

cache = get_config('cache', True) and Cache(CACHE_FILE)
cache = get_config('cache', True)
cache = cache is True and path.join(gettempdir(), 'ddns.cache') or cache
cache = Cache(cache)
if cache is False:
info("Cache is disabled!")
elif get_config("config_modified_time") is None or get_config("config_modified_time") >= cache.time:
Expand Down
8 changes: 6 additions & 2 deletions schema/v2.8.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,17 @@
},
"cache": {
"$id": "/properties/cache",
"type": "boolean",
"type": [
"string",
"boolean"
],
"title": "Enable Cache",
"description": "是否启用缓存记录以避免频繁更新",
"default": true,
"examples": [
true,
false
false,
"/path/to/cache/ddns.cache"
]
}
},
Expand Down

0 comments on commit a1a8f85

Please sign in to comment.