mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-09-14 22:43:16 +08:00
feat: 使用了自定义缓存 cacheKey 的远程订阅 调整为乐观缓存
This commit is contained in:
parent
b083d2d840
commit
e6d1aa1150
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.14.309",
|
"version": "2.14.310",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -14,7 +14,13 @@ import $ from '@/core/app';
|
|||||||
|
|
||||||
const tasks = new Map();
|
const tasks = new Map();
|
||||||
|
|
||||||
export default async function download(rawUrl, ua, timeout, proxy) {
|
export default async function download(
|
||||||
|
rawUrl,
|
||||||
|
ua,
|
||||||
|
timeout,
|
||||||
|
proxy,
|
||||||
|
skipCustomCache,
|
||||||
|
) {
|
||||||
let $arguments = {};
|
let $arguments = {};
|
||||||
let url = rawUrl.replace(/#noFlow$/, '');
|
let url = rawUrl.replace(/#noFlow$/, '');
|
||||||
const rawArgs = url.split('#');
|
const rawArgs = url.split('#');
|
||||||
@ -39,6 +45,23 @@ export default async function download(rawUrl, ua, timeout, proxy) {
|
|||||||
? `#sub-store-cached-custom-${$arguments?.cacheKey}`
|
? `#sub-store-cached-custom-${$arguments?.cacheKey}`
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
if (customCacheKey && !skipCustomCache) {
|
||||||
|
const cached = $.read(customCacheKey);
|
||||||
|
if (cached) {
|
||||||
|
$.info(
|
||||||
|
`乐观缓存: URL ${url}\n本次返回自定义缓存 ${$arguments?.cacheKey}\n并进行请求 尝试更新缓存`,
|
||||||
|
);
|
||||||
|
download(
|
||||||
|
rawUrl.replace(/(\?|&)cacheKey=.*?(&|$)/, ''),
|
||||||
|
ua,
|
||||||
|
timeout,
|
||||||
|
proxy,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// const downloadUrlMatch = url.match(/^\/api\/(file|module)\/(.+)/);
|
// const downloadUrlMatch = url.match(/^\/api\/(file|module)\/(.+)/);
|
||||||
// if (downloadUrlMatch) {
|
// if (downloadUrlMatch) {
|
||||||
// let type = downloadUrlMatch?.[1];
|
// let type = downloadUrlMatch?.[1];
|
||||||
@ -81,7 +104,7 @@ export default async function download(rawUrl, ua, timeout, proxy) {
|
|||||||
|
|
||||||
// try to find in app cache
|
// try to find in app cache
|
||||||
const cached = resourceCache.get(id);
|
const cached = resourceCache.get(id);
|
||||||
if (!$arguments?.noCache && cached) {
|
if (!$arguments?.noCache && cached && !skipCustomCache) {
|
||||||
$.info(`使用缓存: ${url}`);
|
$.info(`使用缓存: ${url}`);
|
||||||
result = cached;
|
result = cached;
|
||||||
} else {
|
} else {
|
||||||
@ -120,6 +143,9 @@ export default async function download(rawUrl, ua, timeout, proxy) {
|
|||||||
if (shouldCache) {
|
if (shouldCache) {
|
||||||
resourceCache.set(id, body);
|
resourceCache.set(id, body);
|
||||||
if (customCacheKey) {
|
if (customCacheKey) {
|
||||||
|
$.info(
|
||||||
|
`URL ${url}\n写入自定义缓存 ${$arguments?.cacheKey}`,
|
||||||
|
);
|
||||||
$.write(body, customCacheKey);
|
$.write(body, customCacheKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user