Update app.py
Browse files
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 |
-
|
108 |
-
return web.Response(text=cache[url], content_type='text/plain'), "Hit"
|
109 |
-
|
110 |
try:
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
return web.Response(text=result, content_type='text/plain'),
|
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:
|