#include "bacula.h"
 #include "filed.h"
+#include "lib/mntent_cache.h"
 
 #ifdef HAVE_PYTHON
 
    bnet_stop_thread_server(server_tid);
    generate_daemon_event(NULL, "Exit");
    unload_plugins();
+   flush_mntent_cache();
    write_state_file(me->working_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs));
    delete_pid_file(me->pid_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs));
 
 
 
 /**
  * Flush the current content from the cache.
- * This function should be called with a write lock on the mntent_cache.
  */
-static void flush_mntent_cache(void)
+void flush_mntent_cache(void)
 {
    /**
-    * Make sure the cache is empty (either by flushing it or by initializing it.)
+    * Lock the cache.
     */
-   clear_mount_cache();
+   P(mntent_cache_lock);
+
+   if (mntent_cache_entry_hashtable) {
+      previous_cache_hit = NULL;
+      mntent_cache_entry_hashtable->destroy();
+      mntent_cache_entry_hashtable = NULL;
+   }
+
+   V(mntent_cache_lock);
 }
 
 /**
     * the lookup again.
     */
    if (!mce) {
-      /**
-       * Make sure the cache is empty (either by flushing it or by initializing it.)
-       */
-      clear_mount_cache();
-
-      /**
-       * Refresh the cache.
-       */
-      refresh_mount_cache();
-
+      initialize_mntent_cache();
       mce = (mntent_cache_entry_t *)mntent_cache_entry_hashtable->lookup(dev);
    }
 
 
 };
 
 mntent_cache_entry_t *find_mntent_mapping(uint32_t dev);
+void flush_mntent_cache(void);
 
 #endif /* _MNTENT_CACHE_H */
 
 
 #include "bacula.h"
 #include "findlib/find.h"
+#include "lib/mntent_cache.h"
 
 /* Dummy functions */
 int generate_daemon_event(JCR *jcr, const char *event) 
       }
    }
 
+   flush_mntent_cache();
+
    exit(status);
 }
 
 #include "bacula.h"
 #include "dird/dird.h"
 #include "findlib/find.h"
+#include "lib/mntent_cache.h"
 #include "ch.h"
 
 #if defined(HAVE_WIN32)
      num_files, max_file_len, max_path_len,
      trunc_fname, trunc_path, hard_links);
 
+   flush_mntent_cache();
+
    term_msg();
 
    close_memory_pool();