From abcf435b2b8da044da8bdc092e7d72f81dfd7982 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 14 May 2017 18:41:47 +0530 Subject: [PATCH] Reset the file cache when starting the embedded server prevents the memory cache from going out of sync with the file system cache on server restart --- src/calibre/srv/content.py | 4 ++++ src/calibre/srv/embedded.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/calibre/srv/content.py b/src/calibre/srv/content.py index 6107184248..2fe64f7933 100644 --- a/src/calibre/srv/content.py +++ b/src/calibre/srv/content.py @@ -43,6 +43,10 @@ mtimes = {} rename_counter = 0 +def reset_caches(): + mtimes.clear() + + def open_for_write(fname): try: return share_open(fname, 'w+b') diff --git a/src/calibre/srv/embedded.py b/src/calibre/srv/embedded.py index 3f5ff38a78..ecabba3f62 100644 --- a/src/calibre/srv/embedded.py +++ b/src/calibre/srv/embedded.py @@ -83,11 +83,13 @@ class Server(object): def serve_forever(self): self.exception = None + from calibre.srv.content import reset_caches if self.state_callback is not None: try: self.state_callback(True) except Exception: pass + reset_caches() # we reset the cache as the server tdir has changed try: self.loop.serve_forever() except BaseException as e: