yangdx commited on
Commit
4fa6126
·
1 Parent(s): 3ab8571

Prevent caching problem of HTML files for web UI

Browse files

- Add NoCacheStaticFiles class
- Set Cache-Control headers for HTML files

lightrag/api/lightrag_server.py CHANGED
@@ -423,12 +423,22 @@ def create_app(args):
423
  "update_status": update_status,
424
  }
425
 
 
 
 
 
 
 
 
 
 
 
426
  # Webui mount webui/index.html
427
  static_dir = Path(__file__).parent / "webui"
428
  static_dir.mkdir(exist_ok=True)
429
  app.mount(
430
  "/webui",
431
- StaticFiles(directory=static_dir, html=True, check_dir=True),
432
  name="webui",
433
  )
434
 
 
423
  "update_status": update_status,
424
  }
425
 
426
+ # Custom StaticFiles class to prevent caching of HTML files
427
+ class NoCacheStaticFiles(StaticFiles):
428
+ async def get_response(self, path: str, scope):
429
+ response = await super().get_response(path, scope)
430
+ if path.endswith('.html'):
431
+ response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
432
+ response.headers['Pragma'] = 'no-cache'
433
+ response.headers['Expires'] = '0'
434
+ return response
435
+
436
  # Webui mount webui/index.html
437
  static_dir = Path(__file__).parent / "webui"
438
  static_dir.mkdir(exist_ok=True)
439
  app.mount(
440
  "/webui",
441
+ NoCacheStaticFiles(directory=static_dir, html=True, check_dir=True),
442
  name="webui",
443
  )
444
 
lightrag_webui/index.html CHANGED
@@ -2,6 +2,9 @@
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8" />
 
 
 
5
  <link rel="icon" type="image/svg+xml" href="/logo.png" />
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>Lightrag</title>
 
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8" />
5
+ <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
6
+ <meta http-equiv="Pragma" content="no-cache" />
7
+ <meta http-equiv="Expires" content="0" />
8
  <link rel="icon" type="image/svg+xml" href="/logo.png" />
9
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10
  <title>Lightrag</title>