sfun commited on
Commit
463028b
1 Parent(s): 96c5682

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -104,19 +104,21 @@ async def handle_request(request):
104
  url = query_params['url'][0]
105
  force_refresh = 'nocache' in query_params
106
 
107
- if not force_refresh and url in cache:
108
- return web.Response(text=cache[url], content_type='text/plain'), "Hit"
109
-
110
  try:
111
- async with aiohttp.ClientSession() as session:
112
- input_text = await fetch_url(url, session)
113
- result = await extract_and_transform_proxies(input_text)
114
-
115
- # 只有在不是强制刷新的情况下才存入缓存
116
- if not force_refresh:
117
- cache[url] = result
 
 
 
 
118
 
119
- return web.Response(text=result, content_type='text/plain'), "Miss"
120
  except Exception as e:
121
  return web.Response(text=f"Error: {str(e)}", status=500), "Error"
122
  else:
 
104
  url = query_params['url'][0]
105
  force_refresh = 'nocache' in query_params
106
 
107
+ cache_status = "Miss"
 
 
108
  try:
109
+ if not force_refresh and url in cache:
110
+ result = cache[url]
111
+ cache_status = "Hit"
112
+ else:
113
+ async with aiohttp.ClientSession() as session:
114
+ input_text = await fetch_url(url, session)
115
+ result = await extract_and_transform_proxies(input_text)
116
+
117
+ # 只有在不是强制刷新的情况下才存入缓存
118
+ if not force_refresh:
119
+ cache[url] = result
120
 
121
+ return web.Response(text=result, content_type='text/plain'), cache_status
122
  except Exception as e:
123
  return web.Response(text=f"Error: {str(e)}", status=500), "Error"
124
  else: