sub-store-org / Sub-Store

Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket!
https://www.notion.so/Sub-Store-6259586994d34c11a4ced5c406264b46
GNU Affero General Public License v3.0
5.41k stars 596 forks source link

刷新订阅时如何缓存资源 #304

Closed kien8995 closed 7 months ago

kien8995 commented 7 months ago

我想在调用函数operator(proxies) {}时缓存一些资源,我使用$substore.write()。 当我单击刷新按钮时,函数operator是否被调用? 或者你有另一种方法可以在 javascript 中做到这一点吗?

abd54c88b8e917b74ef8

xream commented 7 months ago
  1. 图中的按钮是刷新订阅流量信息的按钮
  2. 没看懂你的需求. 你的问题是 "如何进行缓存的读写"?
kien8995 commented 7 months ago

我想将域查找结果缓存在proxy.server中(示例键值对:domain.com:192.168.0.1)。 但是当域数量太多时会超时,所以我想缓存它们

xream commented 7 months ago

参考 https://github.com/xream/scripts/tree/main/surge/modules/sub-store-scripts/check 里的脚本. 里面用到了 const cache = scriptResourceCache

kien8995 commented 7 months ago

scriptResourceCache位于哪里

xream commented 7 months ago

https://github.com/xream/scripts/blob/main/surge/modules/sub-store-scripts/check/availability.js#L26

读取 cache.get(id)

设置 cache.set(id, {})

kien8995 commented 7 months ago

太感谢了